I need suggestions for creating Ant build for multiple servers. I have about 25 servers. If possible, I would like to implement deployment war file for all the servers by running ant once. I have the following issues to consider
The configuration parameters are not the same for all servers.
Some configuration parameters I have to set server host ip on which app is deployed. With 25
servers, want some suggestions on how to deal with this.
You could hand code the logic to do this in Ant, but it might be lot of work depending on how different your server configurations are. Instead, I'd recommend looking at using a proper configuration management tool such as Chef or Puppet to automate your deployments and just use Ant to build the files that are deployed.
I had the same objectives.
You can either code a maven script in order to set up the continuous integration on Jenkins as mentionned by Jayan
or you can create an ANT script like you mentionned.
<!-- Define custom properties -->
<property name="build.dir" location="${basedir}/target" />
<property name="host.dev" value="YOUR IP" />
<property name="host.live" value="YOUR IP 2" />
<property name="ssh.timeout" value="60000" />
<property name="username.dev" value="username" />
<property name="username.live" value="username 2" />
<property name="password.dev" value="password" />
<property name="password.live" value="password 2" />
Create you own ssh macrodef task in order to use ssh commands:
<!-- Define ssh commands sshexec -->
<macrodef name="ssh_cmd">
<attribute name="host" />
<attribute name="command" />
<attribute name="usepty" default="false" />
<attribute name="username" />
<attribute name="password" />
<sequential>
<echo>Executing command : #{command} on #{username}###{host}</echo>
<sshexec host="#{host}" failonerror="true" username="#{username}" password="#{password}" timeout="${ssh.timeout}" command="#{command}" usepty="#{usepty}" trust="true" />
</sequential>
</macrodef>
Send a command to your server like :
<ssh_cmd host="${host.dev}" command="YOUR COMMAND (ex: sudo start yourservice onlinux)" username="${username.dev}" password="${password.dev}"/>
Don't forget to import sshexec / scp ant tasks with something like :
<property environment="env" />
<taskdef resource="net/jtools/classloadertask/antlib.xml">
<classpath>
<fileset dir="${ant.home}/lib" includes="ant-classloader*.jar" />
</classpath>
</taskdef>
Related
I'm running an ant build from Hudson (Ubuntu). The build fails saying:
/var/lib/hudson/jobs/Genesys Multimedia RC/workspace/current/build.xml:34: /var/lib/hudson/jobs/Genesys Multimedia RC/workspace/current/Thirdparty/current does not exist.
Extract of build.xml:
<property name="extraDir" location="Thirdparty" />
<property name="J323ClearJarDir" location="${extraDir}/JRC/Thirdparty/J323/dist" />
<property name="JavaThirdPartyJarDir" location="${extraDir}/current" />
<property name="genesys_jars" location="lib" />
<!--Set the libs needed for compulation-->
<path id="lib">
<fileset dir="${genesys_jars}" includes="*.jar" />
<fileset dir="${JavaThirdPartyJarDir}" includes="*.jar" />
<fileset dir="${frameworkClearJarsDir}" includes="*.jar" />
<fileset dir="${J323ClearJarDir}" includes="*.jar" />
<fileset dir="${jrcClearJarDir}" includes="*.jar" />
</path>
That directory DOES exist however.
And this same build script was working on Hudson (Windows).
Oh what could the matter be?
Linux's filesystem is case sensitive.
The directory is ThirdParty whilst the property was referring to Thirdparty.
I shall be switching careers to become a professional human-lampshade.
config.xml (build file)
Ant script to create An Oracle Service Bus Config Jar from file system.
<target name="run">
<taskdef name="configjar" classname="com.bea.alsb.tools.configjar.ant.ConfigJarTask"/>
<property name="task.failonerror" value="true" />
<property name="task.errorproperty" value="" />
<property name="settingsFile" value="C:\Oracle\Middleware\Oracle_Home\osb\tools\configjar\config.xml"/>
<property name="WL_HOME" value="C:\Oracle\Middleware\Oracle_Home\wlserver" />
<property name="MW_HOME" value="C:\Oracle\Middleware\Oracle_Home\" />
<property name="OSB_HOME" value="C:\Oracle\Middleware\Oracle_Home\osb" />
<!--configjar failonerror="${task.failonerror}" errorProperty="${task.errorproperty}" settingsFile="${settingsFile}" -->
<configjar settingsFile="${settingsFile}" >
</configjar>
</target>
my settings file :
<?xml version="1.0" encoding="utf-8"?>
<configjarSettings xmlns="http://www.bea.com/alsb/tools/configjar/config">
<source>
<project dir="D:\JDeveloper\mywork\ServiceBusApplication2" />
<!--extensionMapping>
<mapping type="str1234" extensions="str1234" />
</extensionMapping-->
<!--fileset>
<include name="str1234" />
<exclude name="str1234" />
</fileset-->
</source>
<configjar jar="SBProject.jar" overwrite="false">
<projectLevel includeSystem="true">
<project>SBProject</project>
</projectLevel>
</configjar>
</configjarSettings>
I have set weblogic environment variable on command prompt , globally using environment variable section of Windows but still not luck.
I am stuck at this point.Need solution on the same.
I am using soa12c.And this is osb script for creation of configuration jar file for osb application.
Go to D:\Oracles\Middleware12c\osb\tools\configjar and run setenv.cmd. On the same cmd try running your ant script. It might ask for MW_HOME, set that also.
Is it possible to do remote deploy of application (jar file) on JBoss using ANT script?
I found only few suggestions to do copy, but that can be done only on local server.
Mainly there are two approaches to do remote JBOSS deploy.
Cargo
This tool providing the ant scripts to do the remote deploy/control JBOSS instance
Copy approach. The main steps are copy the application files to the jboss deploy folder and then start the jboss by remote command.
For example, you can use SCP task to copy the application file to remote host, and then use the SSHEXEC task to remove control the JBOSS_BIN/ shell to start/stop jboss instance.
To deploy remote you can use the jboss-cli, which is included in jboss. To make this approach work you have to have a local jboss install, because it includes the jboss-cli jar. Then you will need a jboss-user on the remote host, which you can create with the add-user.(sh|bat) on the remote box. Then you can use the following ant-tasks to deploy:
<!-- local installation to find the correct jar -->
<property name="local.jboss.home" value="/path/to/jboss/install/dir" />
<!-- remote parts -->
<property name="remote.jboss.host" value="some.ip" />
<property name="remote.jboss.port" value="9999" />
<property name="remote.jboss.user" value="user" />
<property name="remote.jboss.password" value="password" />
<!-- supposedly this is built by a seperate task -->
<property name="my.deployment" value="${basedir}/build/foo.war" />
<!-- preset to run jboss-cli, this can be used to push any command to a running
jboss instance -->
<presetdef name="jboss-cli">
<java jar="${jboss.home}/jboss-modules.jar" fork="true">
<arg line="-mp ${jboss.home}/modules org.jboss.as.cli" />
<arg value="--controller=${jboss.host}:${jboss.port}" />
<arg value="--user=${jboss.user}" />
<arg value="--password=${jboss.password}" />
<arg value="--connect" />
</java>
</presetdef>
<!-- the exec some command on cli command -->
<target name="exec-jboss">
<jboss-cli failonerror="true">
<arg value="${jboss.command}" />
</jboss-cli>
</target>
<target name="deploy" description="deploys to a running jboss instance">
<antcall target="exec-jboss">
<param name="jboss.home" value="${local.jboss.home}" />
<param name="jboss.host" value="${remote.jboss.host}" />
<param name="jboss.port" value="${remote.jboss.port}" />
<param name="jboss.command" value="deploy ${my.deployment}" />
</antcall>
</target>
I am using this script to launch WTP test
<ant target="ui-test" antfile="${eclipse-test-library-file}" dir="${eclipse-test-home}">
<property name="product" value="${productName}" />
<property name="application" value="${applicationName}" />
<property name="os" value="${baseos}"/>
<property name="ws" value="${basews}"/>
<property name="arch" value="${basearch}"/>
<property name="data-dir" value="${eclipse-test-home}/junit-workspace -clean" />
<property name="plugin-name" value="${pluginName}" />
<property name="classname" value="${testClassName}" />
</ant>
The workbench launched but the test did not run. Am I missing something in the ant property?
It's hard to judge what's missing in your setup, but there is an example project for running WindowTester tests from an Ant script here:
http://code.google.com/p/windowtester/downloads/detail?name=WindowTester_AntExample_v1.0.zip
If the example works for you, it should be easy to compare it to your project and find out the difference.
I am a beginner to SONAR , i just need a help for a sample ant build file for running my java project name 'Hello World' with SONAR 's default Sun checks Quality profile .I have not found anywhere any proper ant guide for sonar. I am using SONAR 2.10 .
Please help me in starting with SONAR .
<project name="Example" default="Sonar" basedir=".">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="C:\Program Files\Apache Software Foundation\ant\lib\sonar-ant-task-1.0.jar" />
</taskdef>
<!-- Out-of-the-box those parameters are optional -->
<property name="sonar.jdbc.url" value="jdbc:mysql://localhost:3309/sonar" />
<property name="sonar.jdbc.driverClassName" value="com.mysql.jdbc.Driver" />
<property name="sonar.jdbc.username" value="root" />
<property name="sonar.jdbc.password" value="root" />
<!-- Additional Sonar configuration (PMD need 1.5 when using annotations)-->
<property name="sonar.java.source" value="1.5"/>
<property name="sonar.java.target" value="1.5"/>
<property name="sonar.projectName" value="Example"/>
<property name="sonar.binaries" value="C:\Documents and Settings\tausif\Feature2\Example\bin"/>
<!-- SERVER ON A REMOTE HOST -->
<property name="sonar.host.url" value="http://localhost:8080/sonar" />
<target name="Sonar">
<!-- The workDir directory is used by Sonar to store temporary files -->
<sonar:sonar workDir="C:\Documents and Settings\tausif\Feature2\Sonar" key="com.example:example" xmlns:sonar="antlib:org.sonar.ant" >
<!-- source directories (required) -->
<sources>
<path location="C:\Documents and Settings\tausif\Feature2\Example" />
</sources>
</sonar:sonar>
</target>
</project>
The above two answers were realy helpful for me to create this xml file .
This is my sample build.xml . Can you please check what i am missing in it?
I have made Sun checks as default.My project name is Example.
You might find this (Sonar 2.6: Adds Continuous Inspection Support for Ant Community) or this (Analyse with Ant Task 1.0) documentation helpful.
You can refer below ant script which is specific to the sonar.
You can add it in your build.xml.
Below is the script with the details
<!-- Here you need to set the path which contains sonar specific jars required for ant e.g. path which contains sonar-ant-task-2.1.jar -->
<path id="sonar.classpath">
<fileset dir="${basedir}/sonar" includes="**/*.jar" />
</path>
<!-- This taskdef represents your ant lib for sonar you have to specify jar location along with jar name in class path no need to change the uri and resource-->
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="${basedir}\sonar\sonar-ant-task-2.1.jar" />
</taskdef>
<!-- This is the target we use to run sonar "depends" property is optional -->
<target name="sonar" depends="clean, compile">
<!-- specify your build version -->
<property name="build.version" value="0.0.0.1-Sonar"/>
<!-- specify your organization name its optional -->
<property name="mysonar.organizationName" value="XYZ"/>
<!-- specify your project Name -->
<property name="sonar.projectName" value="${project.name}" />
<!-- database url which is used by the sonar -->
<property name="sonar.jdbc.url" value="jdbc:mysql://<IP>:<Port>/sonar?useUnicode=true&characterEncoding=utf8" />
<!-- Driver name-->
<property name="sonar.jdbc.driverClassName" value="com.mysql.jdbc.Driver" />
<!-- database user name -->
<property name="sonar.jdbc.username" value="test" />
<!-- database password -->
<property name="sonar.jdbc.password" value="test" />
<!-- url on which sonar is running-->
<property name="sonar.host.url" value="http://<IP>:<Port>" />
<!-- project key -->
<property name="sonar.projectKey" value="${mysonar.organizationName}:${sonar.projectName}" />
<!-- project version-->
<property name="sonar.projectVersion" value="1.0" />
<!-- location source files -->
<property name="sonar.sources" value="${src.home}/main/java" />
<!-- location of binaries after compilation-->
<property name="sonar.binaries" value="${basedir}/output"/>
<!-- location of sonar library-->
<sonar:sonar xmlns:sonar="antlib:org.sonar.ant">
</sonar:sonar>
</target>
Note: Make sure that location you specify are correct you can give absolute path as well.