How to deploy configuration files,jars and ear files in remote weblogic server using ant script - ant

I want to deploy the jar files,configuration files and generated ear file on remote weblogic server using ant script.
I have created ant script that stop the weblogic server,delete old files(jar,config xml files,ear) copy the given source to destination,this script is work when source and destination both are having on same machine.
<project name="Svn" default="startserver">
<property name="bea.home" value="C:/Oracle/Middleware/Oracle_Home" />
<property name="weblogic.home" value="${bea.home}/wlserver" />
<property name="domain.home" value="${bea.home}/user_projects/domains" />
<property name="domain.name" value="NAPF_domain" />
<property name="host" value="10.254.5.191" />
<property name="port" value="7001" />
<property name="username" value="weblogic" />
<property name="password" value="weblogic" />
<property name="admin.server.name" value="AdminServer" />
<property name="libdeploy.dir" value="${domain.home}/${domain.name}/lib/" />
<property name="configdeploy.dir" value="${domain.home}/${domain.name}/pf-appl/config/" />
<property name="eardeploy.dir" value="${domain.home}/${domain.name}/servers/AdminServer/upload/" />
<property name="libsource.dir" value="napf-main/napf-build/release/target/Release/lib/" />
<property name="configsource.dir" value="napf-main/napf-build/release/target/Release/config/" />
<property name="earsource.dir" value="napf-main/napf-build/release/target/Release/dist/" />
<property name="napfscutitysource.dir" value="napf-main/napf-security-lib" />
<property name="sourceMonitorHome" location="NAPF_SERVER_SOURCE/SourceMonitor"/>
<path id="wls.classpath">
<fileset dir="${weblogic.home}/server/lib">
<include name="web*.jar" />
</fileset>
</path>
<taskdef name="wlserver" classname="weblogic.ant.taskdefs.management.WLServer" classpathref="wls.classpath" />
<target name="start-server">
<wlserver dir="${domain.home}/${domain.name}" host="${host}" port="${port}" domainname="${domain.name}" servername="${admin.server.name}" action="start" username="${username}" password="${password}" beahome="${bea.home}" weblogichome="${weblogic.home}" verbose="true" noexit="true" protocol="t3" classpath="${weblogic.home}/server/lib/weblogic.jar">
<jvmarg value="-server" />
<jvmarg value="-Xms256m" />
<jvmarg value="-Xmx512m" />
<jvmarg value="-XX:PermSize=128m" />
<jvmarg value="-XX:MaxPermSize=256m" />
</wlserver>
<sleep seconds="2" />
</target>
<target name="stop-server">
<wlserver dir="${domain.home}/${domain.name}" host="${host}" port="${port}" servername="${admin.server.name}" username="${username}" password="${password}" action="shutdown" beahome="${bea.home}" weblogichome="${weblogic.home}" forceshutdown="true" />
</target>
<target name="purge-deploy" description="Delete old deploy files.">
<echo message="Deleting old deploy files..." />
<delete includeEmptyDirs="true">
<!-- Delete all jar files -->
<fileset dir="${libdeploy.dir}" includes="**/*" />
<!-- Delete all config files -->
<fileset dir="${configdeploy.dir}" includes="**/*" />
</delete>
</target>
<target name="copyToSecurityLib" description="Copy files to napf security folder.">
<copy todir="${libdeploy.dir}">
<fileset dir="${napfscutitysource.dir}">
<include name="**" />
<!-- ignore files/folders starting with svn -->
<exclude name="**/.svn" />
</fileset>
</copy>
</target>
<target name="copyToDeploy" description="Copy files to deploy folder.">
<copy todir="${libdeploy.dir}">
<fileset dir="${libsource.dir}">
<include name="**" />
<!-- ignore files/folders starting with svn -->
<exclude name="**/.svn" />
</fileset>
</copy>
<copy todir="${configdeploy.dir}">
<fileset dir="${configsource.dir}">
<include name="**" />
<!-- ignore files/folders starting with svn -->
<exclude name="**/.svn" />
</fileset>
</copy>
<copy todir="${eardeploy.dir}">
<fileset dir="${earsource.dir}">
<include name="**" />
<!-- ignore files/folders starting with svn -->
<exclude name="**/.svn" />
</fileset>
</copy>
</target>
<target name="purgeReport" description="Delete old report files.">
<echo message="Deleting old report files..." />
<delete includeEmptyDirs="true">
<fileset dir="${sourceMonitorHome}" includes="**/*.csv,*.jpeg,*.smp" />
</delete>
</target>
<target name="startSourceMonitor">
<exec dir="${sourceMonitorHome}" executable="cmd" failonerror="true" spawn="false">
<arg value="/c"/>
<arg value="sourcemonitor.bat"/>
</exec>
</target>
<target name="copyReportFiles" description="Copy files to napf source directory to slave workspace directory.">
<delete includeEmptyDirs="true">
<fileset dir="${sourceMonitorWorkSpace}"/>
</delete>
<mkdir dir="${sourceMonitorWorkSpace}"/>
<sleep seconds="1" />
<copy todir="${sourceMonitorWorkSpace}">
<fileset dir="${sourceMonitorHome}">
<include name="**/*.csv" />
<include name="**/*.jpeg" />
<exclude name="**/.svn" />
</fileset>
</copy>
</target>
Please suggest.

You can try wldeploy Ant task.
First, add task definition.
<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
<classpath>
<pathelement location="${weblogic.home}/server/lib/weblogic.jar"/>
</classpath>
</taskdef>
Next, configure each action of wldeploy task, such as deploy, redeploy, or undeploy specifically.
Example,
<!-- The deployment name for the deployed application.
If you do not specify this attribute, WebLogic Server assigns a deployment name to the application, based on its archive file or exploded directory. -->
<property name="deploy.name" value="MyApp"/>
<!-- The archive file or exploded directory to deploy. -->
<property name="deploy.source" value="MyApp.ear"/>
<!-- The list of target servers to which the application is deployed.
The value of this attribute is a comma-separated list of the target servers, clusters, or virtual hosts.
If you do not specify a target list when deploying an application, the target defaults to the Administration Server instance. -->
<property name="deploy.targets" value="MyCluster"/>
<!-- Deploying Applications -->
<target name="deploy">
<wldeploy action="deploy"
name="${deploy.name}"
user="${username}"
password="${password}"
remote="true"
adminurl="t3://${host}:${port}"
source="${deploy.source}"
targets="${deploy.targets}"/>
</target>
<!-- Redeploying Applications -->
<target name="redeploy">
<wldeploy action="redeploy"
name="${deploy.name}"
user="${username}"
password="${password}"
remote="true"
adminurl="t3://${host}:${port}"
targets="${deploy.targets}"/>
</target>
<!-- Undeploying Applications -->
<target name="undeploy">
<wldeploy action="undeploy"
name="${deploy.name}"
failonerror="false"
user="${username}"
password="${password}"
remote="true"
adminurl="t3://${host}:${port}"
targets="${deploy.targets}"/>
</target>
Please note that if we want to deploy the JAR or EAR to remote WebLogic server, we must explicitly set the remote attribute in wldeploy tag to true, since the default value is false.
More complete reference regarding the task can be found on https://docs.oracle.com/cd/E12839_01/web.1111/e13706/wldeploy.htm

The above task would work if you are just specifying the remote server file path. Essentially you would need two parameters one is remote and other being upload.
The same would work but i see an parameter is missing for the task if you are deploying from a remote server
<target name="deploy1">
<wldeploy action="deploy"
upload="true"
remote="true"
name="${deploy.name.1}"
source="${deploy.source.1}"
user="${wls.username}"
password="${wls.password}"
verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

Related

Build fails on Jenkins but works in Eclipse

I got a Spring project built using Ant that fails when executed on Jenkins, but not when I run the exact same Ant target from Eclipse (Ant view).
Jenkins version is 2.19.4
Jenkins Console Output excerpt
Started by user Morin, Charles
Building in workspace D:\APPS\jenkins-2.19.4\workspace\MY-PROJECT
Using locally configured password for connection to :pserver:MY-SERVICE-ACCOUNT#MY-CVS-SERVER:D:/DATA/REPOSITORIES/MY-CVS-REPO
cvs update -d -P -r HEAD -D 26 Jan 2017 10:09:39 -0500 MY-PROJECT
Using locally configured password for connection to :pserver:MY-SERVICE-ACCOUNT#MY-CVS-SERVER:D:/DATA/REPOSITORIES/MY-CVS-REPO
cvs rlog -S -d25 Jan 2017 00:08:54 -0500<26 Jan 2017 10:09:39 -0500 MY-PROJECT
[MY-PROJECT] $ cmd.exe /C "D:\APPS\jenkins-2.19.4\ant\bin\ant.bat -file build.xml compile && exit %%ERRORLEVEL%%"
Buildfile: build.xml
[echo] ========================================================================
[echo] *** Starting MY-PROJECT build
[echo] ========================================================================
print-version:
[echo] Java/JVM version: 1.6
[echo] Java/JVM detailed version: 1.7.0_25
create-directories:
compile:
[javac] Compiling 41 source files to D:\APPS\jenkins-2.19.4\workspace\MY-PROJECT\target\classes
[javac] Note: Hibernate JPA 2 Static-Metamodel Generator 5.1.0.Final
[javac] D:\APPS\jenkins-2.19.4\workspace\MY-PROJECT\src\path\to\my\class\MyClass.java:28: error: cannot find symbol
[javac] import path.to.my.class.MyClass_;
[javac] ^
[javac] symbol: class MyClass_
[javac] location: package path.to.my.class
The problem is that my JPA metamodels are not being found during the compilation. However, we can see the following line that confirms the generation of JPA Metamodels:
Note: Hibernate JPA 2 Static-Metamodel Generator 5.1.0.Final
The only difference I can see is in the print-version Ant target. When executed locally, I got this:
print-version:
[echo] Java/JVM version: 1.7
[echo] Java/JVM detailed version: 1.7.0_25
I also have several other projects with the exact same setup, and I don't have that issue.
build.xml
<?xml version="1.0" encoding="utf-8"?>
<project name="MY-PROJECT" default="create-war-and-deploy-to-jboss" basedir="." xmlns:sonar="antlib:org.sonar.ant" xmlns:jacoco="antlib:org.jacoco.ant">
<property name="verbose" value="false" />
<property name="javaVersion" value="1.7" />
<!-- Provides access to OS environment variables (eg: env.USERNAME) -->
<property environment="env" />
<!-- Application's directories -->
<property name="dir.build" value="${basedir}/build" />
<property name="dir.src" value="${basedir}/src" />
<property name="dir.dist" value="${basedir}/dist" />
<property name="dir.lib" location="${basedir}/lib" />
<property name="dir.target" value="${basedir}/target" />
<property name="dir.build.classes" value="${dir.target}/classes" />
<property name="dir.test" value="${basedir}/test" />
<property name="dir.web" value="${basedir}/WebContent" />
<property name="dir.webinf.lib" value="${dir.web}/WEB-INF/lib" />
<!-- Loading the application.properties file -->
<property file="${dir.src}/resources/application.properties" prefix="app." />
<!-- Loading the build.properties file -->
<property file="build.properties" prefix="buildProp." />
<tstamp>
<format property="build.time" pattern="yyyy-MM-dd HH:mm" />
</tstamp>
<echo message="========================================================================" />
<echo message="*** Starting ${app.name} build " />
<echo message="========================================================================" />
<!-- JBoss directories -->
<property name="dir.jboss" value="${buildProp.jboss.home}" />
<property name="dir.jboss.domain" value="${dir.jboss}/${buildProp.jboss.domain}" />
<property name="dir.jboss.libs" value="${dir.jboss}/${buildProp.jboss.libs}" />
<property name="dir.jboss.deploy" value="${dir.jboss.domain}/${buildProp.jboss.deploy}" />
<!-- Path for unit tests -->
<path id="run.classpath.tests">
<pathelement path="${dir.build.classes}" />
<pathelement path="${dir.test}/build/classes" />
<path refid="compile.classpath.tests" />
</path>
<!-- Provided dependencies from the container -->
<path id="compile.classpath.server">
<fileset dir="${dir.lib}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- Dependencies specific to this application -->
<path id="compile.classpath.web">
<fileset dir="${dir.web}/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
</path>
<path id="compile.classpath.target">
<fileset dir="${dir.lib}">
<include name="hibernate-jpamodelgen-5.1.0.Final.jar" />
</fileset>
<fileset dir="${dir.target}">
<include name="**/*.java" />
</fileset>
</path>
<!-- Dependencies specifically for unit testing purposes -->
<path id="compile.classpath.tests">
<fileset dir="${dir.test}/lib/">
<include name="junit-4.6.jar" />
<include name="mockito-all-1.9.5.jar" />
</fileset>
<fileset dir="${dir.webinf.lib}" />
<pathelement location="${dir.build.classes}" />
<path refid="compile.classpath.server" />
</path>
<!-- PRINT-VERSION -->
<target name="print-version">
<echo>Java/JVM version: ${ant.java.version}</echo>
<echo>Java/JVM detailed version: ${java.version}</echo>
</target>
<!-- BUILD-DISTRIBUTION -->
<target
name="build-distribution"
description="Generate Deployment unit and stage to appserver directory."
depends="
clean,
run-unit-tests,
create-war,
run-sonarqube-analysis">
<manifest file="${dir.web}/META-INF/MANIFEST.MF">
<attribute name="Manifest-Version" value="1.0" />
<attribute name="Ant-Version" value="1.7.0" />
<attribute name="Created-By" value="${env.USERNAME}" />
<attribute name="Implementation-Title" value="${app.name}" />
<attribute name="Implementation-Version" value="${app.version}" />
<attribute name="Implementation-Vendor" value="Canada Revenue Agency" />
<attribute name="Implementation-Date" value="${build.time}" />
<attribute name="Built-By" value="${env.USERNAME}" />
<attribute name="Dependencies" value="org.hibernate" />
</manifest>
<propertyfile file="${dir.src}/resources/application.properties">
<entry key="lastUpdate" value="${build.time}" />
</propertyfile>
</target>
<!-- CLEAN -->
<target name="clean"
description="Cleans up build-related temporary directories."
depends="delete-directories" />
<!-- CREATE-DIRECTORIES -->
<target name="create-directories" >
<mkdir dir="${dir.build}" />
<mkdir dir="${dir.dist}" />
<mkdir dir="${dir.build.classes}" />
<mkdir dir="${dir.web}/WEB-INF/classes" />
<mkdir dir="${dir.test}/build" />
<mkdir dir="${dir.test}/build/classes" />
<mkdir dir="${dir.test}/reports" />
</target>
<!-- DELETES-DIRECTORIES -->
<target name="delete-directories">
<delete dir=".sonar" />
<!-- /build -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.build}" includes="**/*" />
<exclude name=".cvsignore" />
</delete>
<!-- /dist -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.dist}" includes="**/*" />
<exclude name=".cvsignore" />
</delete>
<!-- /WEB-INF/classes -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.web}/WEB-INF/classes">
<include name="**/*" />
</fileset>
<fileset dir="${dir.web}/WEB-INF/src">
<include name="**/*" />
</fileset>
</delete>
<!-- /target -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.target}" includes="**/*" />
<exclude name=".cvsignore" />
</delete>
<!-- /test/build -->
<delete dir="${dir.test}/build" />
<!-- /test/reports -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.test}/reports" />
</delete>
<!-- Existing WAR file and JBoss marker files -->
<delete dir="${dir.jboss.deploy}/${app.name}.war" />
<delete file="${dir.jboss.deploy}/${app.name}.war" />
<delete file="${dir.jboss.deploy}/${app.name}.war.deployed" />
</target>
<!-- COMPILE -->
<target name="compile" depends="print-version,create-directories">
<javac destdir="${dir.build.classes}" verbose="${verbose}" debug="on" fork="true" failonerror="true" source="${javaVersion}" target="${javaVersion}" includeantruntime="false">
<classpath>
<path refid="compile.classpath.server" />
<path refid="compile.classpath.target" />
<path refid="compile.classpath.web" />
</classpath>
<src path="${dir.src}" />
<compilerarg value="-Xlint:deprecation" />
<compilerarg value="-Xlint:unchecked" />
</javac>
<!--copy property files to classes directory -->
<copy todir="${dir.build.classes}">
<fileset dir="${dir.src}">
<include name="**/*.properties" />
<include name="META-INF/**/*" />
</fileset>
</copy>
</target>
<!-- COMPILE-TESTS -->
<target name="compile-tests" depends="create-directories,compile">
<javac srcdir="${dir.test}/src" destdir="${dir.test}/build/classes" verbose="${verbose}" debug="on" fork="true" source="${javaVersion}" target="${javaVersion}" includeantruntime="false">
<classpath refid="compile.classpath.tests" />
<compilerarg value="-Xlint:deprecation" />
<compilerarg value="-Xlint:unchecked" />
</javac>
</target>
<!-- RUN-UNIT-TESTS -->
<target name="run-unit-tests" depends="compile-tests" description="Runs all unit test classes under the test package.">
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="test/lib/org.jacoco.ant-0.7.2.201409121644.jar"/>
<classpath path="test/lib/org.jacoco.agent_0.7.2.201409121644.jar"/>
<classpath path="test/lib/org.jacoco.core_0.7.2.201409121644.jar"/>
<classpath path="test/lib/org.jacoco.report_0.7.2.201409121644.jar"/>
</taskdef>
<jacoco:coverage destfile="${dir.target}/jacoco.exec">
<junit fork="true" printsummary="yes" haltonfailure="yes" showoutput="no">
<classpath refid="run.classpath.tests" />
<formatter type="xml" />
<batchtest fork="yes" todir="${dir.test}/reports">
<fileset dir="${dir.test}/src">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
<!-- CREATE-WAR -->
<target name="create-war" description="Creates a WAR file including all compiled classes and resources." depends="compile">
<war destfile="dist/${app.name}.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent" />
<classes dir="${dir.build.classes}" />
</war>
</target>
<!-- CREATE-WAR-AND-DEPLOY -->
<target name="create-war-and-deploy-to-jboss" description="Creates a WAR file including all compiled classes and resources, and deploys the app to jboss" depends="create-war,deploy-to-jboss" />
<!-- RUN-SONARQUBE -->
<target name="run-sonarqube-analysis" description="Runs the SonarQube analysis and updates statistics on the server." depends="create-war">
<property file="sonar.properties" prefix="sonar." />
<!-- SonarQube properties -->
<property name="sonar.exclusions" value="${sonar.exclusions}" />
<property name="sonar.host.url" value="${sonar.host.url}" />
<property name="sonar.jacoco.reportPath" value="${sonar.jacoco.reportPath}" />
<property name="sonar.java.binaries" value="${sonar.java.binaries}" />
<property name="sonar.java.coveragePlugin" value="${sonar.java.coveragePlugin}" />
<property name="sonar.java.libraries" value="${sonar.java.libraries}" />
<property name="sonar.java.source" value="${javaVersion}" />
<property name="sonar.junit.reportsPath" value="${sonar.junit.reportsPath}" />
<property name="sonar.projectKey" value="${sonar.projectKey}" />
<property name="sonar.projectVersion" value="${app.version}" />
<property name="sonar.projectName" value="${sonar.projectName}" />
<property name="sonar.sources" value="${sonar.sources}" />
<property name="sonar.sourceEncoding" value="${sonar.sources.sourceEncoding}" />
<property name="sonar.tests" value="${sonar.tests}" />
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="${dir.lib}/sonarqube-ant-task-2.4.1.jar" />
</taskdef>
<sonar:sonar/>
</target>
<!-- DEPLOY-TO-JBOSS -->
<target name="deploy-to-jboss" depends="create-war">
<!--delete war file if it already exists and was copied over, we need a directory now-->
<delete file="${dir.jboss.deploy}/${app.name}.war" />
<delete file="${dir.jboss.deploy}/${app.name}.war.deployed" />
<!-- copy all of the files except one that will trigger the deployment -->
<copy todir="${dir.jboss.deploy}">
<fileset file="${dir.dist}/${app.name}.war" />
</copy>
</target>
</project>
Thank you
From Manage Jenkins-->Configure System--JDK section, add both JDKs to JDK Installation. From your Job Configuration, in the JDK section, explicitly choose the 1.7 JDK.

Ant task "javac" was successful but doesn't produce any output

I'm trying to compile a project using ant. I guess the "javac" task was successful as i can see the following message on the console:
[javac] Compiling 151 source file to /var/lib/jenkins/jobs/project1/workspace/build
Here is the complete output of the command "ant compile"
clean:
[delete] Deleting directory /var/lib/jenkins/jobs/project1/workspace/build
[delete] Deleting directory /var/lib/jenkins/jobs/project1/workspace/docs
[delete] Deleting directory /var/lib/jenkins/jobs/project1/workspace/dist
makedir:
[mkdir] Created dir: /var/lib/jenkins/jobs/project1/workspace/build
[mkdir] Created dir: /var/lib/jenkins/jobs/project1/workspace/docs
[mkdir] Created dir: /var/lib/jenkins/jobs/project1/workspace/dist
compile:
[javac] /var/lib/jenkins/jobs/project1/workspace/build.xml:43: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 151 source file to /var/lib/jenkins/jobs/project1/workspace/build
BUILD SUCCESSFUL
Total time: 1 second
The problem is there is nothing produced in the folder "build" !
I'm using the same build.xml template file in other projects and it works very well, but here i can't understand why i can't find the compiled sources in the build folder.
Please help.
Here is my build.xml file:
<?xml version="1.0"?>
<project name="project1" default="main" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="lib.dir" location="WebContent/WEB-INF/lib" />
<property name="server.common.lib.dir" location="/home/ghali/jboss-5.1.0.GA/common/lib" />
<property name="server.lib.dir" location="/home/ghali/jboss-5.1.0.GA/lib" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="docs.dir" location="docs" />
<!--
Create a classpath container which can be later used in the ant task
-->
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${server.common.lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${server.lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Compiles the java code -->
<target name="compile" depends="clean, makedir">
<javac destdir="${build.dir}" classpathref="build.classpath" debug="true">
<src path="${src.dir}" />
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc sourcepath="${src.dir}" destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="**" />
</fileset>
</javadoc>
</target>
<!--Creates the deployable jar file -->
<target name="package" depends="compile">
<war destfile="${dist.dir}/project1.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent" />
<lib dir="WebContent/WEB-INF/lib" />
<classes dir="${build.dir}" />
</war>
</target>
<target name="main" depends="compile, package, docs">
<description>Main target</description>
</target>
</project>

Compiled classes are not included in generated Jar

I am creating a jar bundle using ant build script. The problem is that the .class files are not included in the generated .jar file. I have also tried the {build.dest} in making the jar, but with no effect.
remaining all the files i require are in .jar file.
Here is my build script
<?xml version="1.0"?>
<project name="TaskNodeBundle" default="all" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="bundlename" value="task-node-bundle" />
<property name="src.dir" location="../src" />
<property name="lib.dir" location="../lib" />
<property name="build.dir" location="/buildoutput" />
<property name="build.dest" location="../build/dest" />
<!--
Create a classpath container which can be later used in the ant task
-->
<path id="classpath">
<fileset dir="${lib.dir}/">
<include name="*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${build.dest}" />
</target>
<!-- Deletes the existing build directory -->
<target name="mkdir" depends="clean">
<mkdir dir="${build.dest}"/>
</target>
<!-- Compiles the java code -->
<target name="compile" depends="mkdir">
<javac srcdir="${src.dir}" destdir="${build.dest}" classpathref="classpath" />
</target>
<target name="package-bundle" depends="compile" description="Generates the bundle" >
<jar destfile="${build.dest}/${bundlename}.jar" manifest="${src.dir}/META-INF/MANIFEST.MF">
<fileset dir="${src.dir}">
<include name="**/**.class" />
<include name="**/**.properties"/>
<include name="/META-INF/**.*" />
<include name="/META-INF/spring/**.*" />
</fileset>
</jar>
</target>
<target name="all" depends="package-bundle">
</target>
</project>
Firstly, what do you mean by "tried {build.dest} in making the jar"?
Whatever, you need to take a look at this part of your build:
<jar destfile="${build.dest}/${bundlename}.jar" manifest="${src.dir}/META-INF/MANIFEST.MF">
<fileset dir="${src.dir}">
<include name="**/**.class" />
<include name="**/**.properties"/>
<include name="/META-INF/**.*" />
<include name="/META-INF/spring/**.*" />
</fileset>
</jar>
You compiled class files are in ${build.dest}, so you should use ${build.dest} as the root dir for the nested <fileset> of the <jar> task. But now you are pointing the <fileset> to your source code folder.
You should avoid putting the generated jar file in the same directory where the class files are. For example, you can put the jar in ${dist.dir}, which is another directory.
So try this:
You have a property:
<property name="dist.dir" value="../build/dist" />
And then,
<jar destfile="${dist.dir}/${bundlename}.jar" manifest="${src.dir}/META-INF/MANIFEST.MF">
<fileset dir="${build.dest}">
<include name="**/*.class" />
</fileset>
<fileset dir="${src.dir}">
<include name="**/*.properties"/>
<include name="/META-INF/**/*.*" />
<include name="/META-INF/spring/**/*.*" />
</fileset>
</jar>

MANIFEST.MF is override after running build.xml using ant

have following directory structure
src/com
src/META-INF/MANIFEST.MF
src/META-INF/spring
src/META-INF/spring/context.xml
now when i run the script, my menifest file is override, i don't want that, because i have to add custom enteries in it and i want that to be adding in generated .jar file. THing is all other files are copied, but this one is override.
my build.xml is as follows
<project name="TaskNodeBundle" default="all" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="bundlename" value="tasknodebundle" />
<property name="src.dir" location="../src" />
<property name="lib.dir" location="../lib" />
<property name="build.dir" location="/buildoutput" />
<property name="build.dest" location="../build/dest" />
<!--
Create a classpath container which can be later used in the ant task
-->
<path id="classpath">
<fileset dir="${lib.dir}/">
<include name="*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${build.dest}" />
</target>
<!-- Deletes the existing build directory-->
<target name="mkdir" depends="clean">
<mkdir dir="${build.dest}"/>
</target>
<!-- Compiles the java code -->
<target name="compile" depends="mkdir">
<javac srcdir="${src.dir}" destdir="${build.dest}" classpathref="classpath" />
</target>
<target name="package-bundle" depends="compile" description="Generates the bundle">
<jar destfile="${build.dest}/${bundlename}.jar">
<fileset dir="${src.dir}">
<include name="**/**.class" />
<include name="**/**.properties"/>
<include name="/META-INF/**.*" />
<include name="/META-INF/spring/**.*" />
</fileset>
</jar>
</target>
<target name="all" depends="package-bundle">
</target>
</project>
See http://ant.apache.org/manual/Tasks/jar.html.
If the manifest is omitted, a simple one will be supplied by Apache
Ant.
Just add manifest attribute or use zip task.
Also ant path masks are used incorrectly. See http://en.wikibooks.org/wiki/Apache_Ant/Fileset.
Corrected version:
<zip destfile="${build.dest}/${bundlename}.jar">
<fileset dir="${src.dir}">
<include name="META-INF/**" />
<include name="**/*.class" />
<include name="**/*.properties"/>
</fileset>
</zip>

Ant not running all targets

I have the following ant file that is not running the targets "prepForDeployment" and "deployToStaging". This task is being run by Jenkins and I'm not getting any build errors when I look at the console output of the test.
<?xml version="1.0" encoding="UTF-8"?>
<project name="deploy" default="runUnitTests" basedir=".">
<description>
Deploys to staging.
</description>
<target name="init">
<taskdef name="mxunittask" classname="org.mxunit.ant.MXUnitAntTask" classpathref="project.classpath" />
<!-- dump the properties -->
<echoproperties prefix="test" />
</target>
<target name="clean" depends="init">
<mkdir dir="${test.junitoutput}" />
</target>
<target name="runUnitTests" depends="init,prepForTests">
<mkdir dir="${test.output.xml}/unit" />
<runTestDirectory directoryName="." excludes=""/>
</target>
<target name="runAllTests" description="Make output directories and run the MXUnit task" depends="init,clean,runUnitTests">
<!-- generate pretty reports -->
<antcall target="junitreport" />
<fail if="tests.bombed" message="Failing the build due to test failures"/>
</target>
<target name="junitreport" depends="init" description="Runs the report without running the tests">
<junitreport todir="${test.junitoutput}">
<fileset dir="${test.output.xml}">
<include name="*.xml" />
</fileset>
<report format="frames" todir="${test.junitoutput}" />
</junitreport>
</target>
<target name="prepForTests">
<!-- just a bunch of replace tasks, runs OK -->
</target>
<target name="prepForDeployment" depends="init">
<replace file="Application.cfc">
<replacetoken>dbcreate="dropcreate"</replacetoken>
<replacevalue>dbcreate="update"</replacevalue>
</replace>
<replace file="Application.cfc">
<replacetoken>logSQL = true</replacetoken>
<replacevalue>logSQL = false</replacevalue>
</replace>
<echo message="Prepping for deployment done." />
</target>
<target name="deployToStaging" depends="prepForDeployment">
<sequential>
<!--copy the files to a temp directory-->
<copy todir="${staging}_temp" overwrite="true">
<!-- -->
</copy>
<!-- delete applicaiton files on staging -->
<delete quiet="true" includeemptydirs="true">
<fileset dir="${staging}" />
</delete>
<!-- copy files from temp dir to application dir -->
<copy todir="${staging}" overwrite="true">
<fileset dir="${staging}_temp" />
</copy>
<!-- remove temp dir -->
<delete quiet="true" includeemptydirs="true">
<fileset dir="${staging}_temp" />
</delete>
</sequential>
<echo message="The files have been copied to staging." />
</target>
<macrodef name="runTestDirectory">
<attribute name="directoryName"/>
<attribute name="excludes" default=""/>
<sequential>
<mxunittask server="${test.server}" port="${test.serverport}" defaultrunner="${test.runner}" outputdir="${test.output.xml}/#{directoryName}" verbose="true" failureproperty="tests.bombed" errorproperty="tests.bombed">
<directory path="${test.dir.location}/#{directoryName}" recurse="true" packageName="${test.cfcpath}.#{directoryName}" componentPath="${test.cfcpath}.#{directoryName}" excludes="#{excludes}" />
</mxunittask>
</sequential>
</macrodef>
</project>
If you're not telling Jenkins to run the prepForDeployment and deployToStaging targets then it won't run them, just the same as when you run Ant on the command line.
If you want those targets to run, add them to the target list under your "Invoke Ant" build step.

Resources