Reputation: 3609
In our company many projects on Java and a build.xml that should compile, clean and run all code, so build.xml doesn't compile the code and .jar doesn't creating either. build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="java" basedir=".">
<description>Builds, tests, and runs the project front_web.</description>
<property name="project.location" value="C:\apache\repp_copy\Java\processing" />
<property name="webapps.location" value="C:\apache-tomcat-6.0.36\webapps" />
<path id="project.class.path">
<pathelement location="C:\apache\repp_copy\Java\processing\lib\servlet-api.jar" />
<pathelement location="C:\apache\repp_copy\Java\processing\lib\log4j-1.2.16.jar" />
<pathelement location="C:\apache\repp_copy\Java\processing\lib\mailapi.jar" />
</path>
<target name="compile" depends="clean">
<javac srcdir="src" destdir="Build/tnxBuild" debug="true" encoding="utf-8">
<classpath refid="project.class.path" />
</javac>
<copy todir="Build/tnxBuild">
<fileset dir="src">
<include name="*.properties"/>
</fileset>
</copy>
</target>
<target name="compileMcVpc" depends="clean, compile">
<javac srcdir="module-thx/src" destdir="Build/tnxBuild" debug="true" encoding="utf-8">
<classpath refid="project.class.path" />
</javac>
<copy todir="Build/tnxBuild">
<fileset dir="module-thx/src">
<include name="*.properties"/>
</fileset>
</copy>
</target>
<fileset id="common" dir="lib">
<include name="*.jar" />
</fileset>
<target name="createJar" depends="compileMcVpc,clean,compile">
<war destfile="thx.jar" webxml="module-thx/web/WEB-INF/web.xml">
<lib refid="common" />
<classes dir="${project.location}/Build/tnxBuild">
</classes>
<metainf file="module-thx/web/META-INF/context.xml">
</metainf>
<fileset id="content" dir="${project.location}/module-thx/web">
<include name="*/*.*" />
<include name="*.*" />
</fileset>
<!--<metainf file="front_web/web/META-INF/context.xml">
</metainf>-->
<!--<fileset id="content" dir=".">
<include name="*.*" />
</fileset>-->
</war>
</target>
<target name="clean">
<delete dir="Build/tnxBuild" />
<mkdir dir="Build/tnxBuild" />
</target>
<target name="runApp" depends="createJar">
<delete dir="${webapps.location}/thx.jar" />
<copyfile src="thx.jar" dest="C:\apache\repp_copy\Java\processing\jars\thx.jar" />
<delete dir="thx.jar" />
</target>
</project>
PS all directories are right, double checked. The result from console:
Buildfile: C:\apache\repp_copy\Java\processing\build-Tnx.xml
BUILD SUCCESSFUL
Total time: 422 milliseconds
Upvotes: 0
Views: 124
Reputation: 10028
Look at the dependencies listed for the "createJar" target.
<target name="createJar" depends="compileMcVpc,clean,compile">
If you call the createJar target, before it runs, ant will call compileMcVpc, clean and compile, in that order.
The JAR task reads in files that are built during compileMcVpc and then deleted by clean. So by the time createJar begins doing its work, the files it needs are gone.
Now what is a little interesting is that you have 2 targets, compileMcVpc, which both output java bytecode to the same directory. Given the order of your targets, I would expect that the "src" classes would be in the JAR but not the "module-thx/source" jars.
Try straightening out your dependencies. To simplify and debug, maybe remove all dependencies directly in the order you want them to run without ant doing it for you. If that works, it proves the dependencies are at fault.
Upvotes: 1