Collection of great links to ant tutorials, docs, types, etc.
If you're confused about environment variables or other issues on Linux or Windows, read these steps carefully as I tell you enough across all steps to perform what's needed on both platforms although you might be learning in a subsequent step how to do something on your platform in an earlier one. (Have I confused you more?)
Start -> Control Panel -> System -> Advanced system settings -> Environment Variables -> User variables
C:\Users\russ\dev\workspaces\workspace\Fun>dir %JAVA_HOME%\bin\java.exe
~/dev/workspaces/workspace/Fun > set $PATH="$PATH:$ANT_HOME/bin"
C:\Users\russ\dev\workspaces\workspace\Fun>ant -version Apache Ant version 1.8.1 compiled on April 30 2010
These are hard to find for some reason.
Here's how to get at your own system's environment from ant:
<property environment="env" /> <echo> Hostname: ${env.COMPUTERNAME} </echo> <echo> Path: ${env.Path} </echo>
If you see something very unpleasant like:
C:\Users\russ\1. dev\workspaces\android-workspace\ScoreModel>ant show-vars Buildfile: C:\Users\russ\dev\workspaces\workspace\Fun\build.xml show-vars: [echo] build.dir=. [echo] classes.dir=${build.dir}/classes [echo] test.classes.dir=./test [echo] jar.dir=${build.dir}/jar [echo] src.dir=./src [echo] lib.dir=./lib BUILD SUCCESSFUL Total time: 0 seconds
...and you're tempted to scream, "Why does ${build.dir} expand correctly some of the time, as used to define src.dir, and not others, for example, classes.dir?", stop and remember that you defined build.dir too late, or that you're working with two files, for example, build.xml which includes build-commons.xml (the one defining build.dir) later than classes.dir was defined by the first. Don't panic, just open your eyes!
(Obviously, I'm embarrassing myself by even noting a solution to this problem, but then I've a lot to be humble about: I'm not always the brightest Crayola™ in the box.)
Stackoverflow answers this question.
This stuff was generated by Eclipse pursuant to an Export command.
Setting up the classpath(s).
<path id="junit4.libraryclasspath"> <pathelement location="${ECLIPSE_HOME}/plugins/org.junit_4.8.1.v4_8_1_v20100427-1100/junit.jar" /> <pathelement location="${ECLIPSE_HOME}/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar" /> </path> ... <path id="myapplication.classpath"> <pathelement location="build/classes" /> <path refid="Apache Tomcat v6.0 [Apache Tomcat v6.0].libraryclasspath" /> <path refid="junit4.libraryclasspath" /> <pathelement location="lib/apache/log4j-1.2.16.jar" /> <pathelement location="lib/apache/servlet-api.jar" /> <pathelement location="lib/hibernate/antlr-2.7.6.jar" /> <pathelement location="lib/hibernate/c3p0-0.9.1.jar" /> <pathelement location="lib/hibernate/hibernate-jpa-2.0-api-1.0.1.Final.jar" /> <pathelement location="lib/hibernate/hibernate3.jar" /> <pathelement location="lib/hibernate/javassist-3.12.0.GA.jar" /> <pathelement location="lib/jboss/webplatform-servicelocator-1.0.jar" /> <pathelement location="lib/jersey/asm-3.1.jar" /> <pathelement location="lib/jersey/jersey-client-1.6.jar" /> <pathelement location="lib/jersey/jersey-core-1.6.jar" /> <pathelement location="lib/jersey/jersey-json-1.6.jar" /> <pathelement location="lib/jersey/jersey-server-1.6.jar" /> <pathelement location="lib/jersey/oauth-server-1.10.jar" /> <pathelement location="lib/jersey/oauth-signature-1.10.jar" /> <pathelement location="lib/mysql/mysql-connector-java-5.1.16-bin.jar" /> <pathelement location="lib/mongo/mongo-2.6.3.jar" /> <pathelement location="lib/mongo/morphia-0.99.jar" /> <pathelement location="lib/apache/commons-collections-3.1.jar" /> <pathelement location="lib/apache/commons-configuration-1.7.jar" /> <pathelement location="lib/apache/commons-lang-2.6.jar" /> <pathelement location="lib/gson/gson-1.7.1.jar" /> <pathelement location="lib/hibernate/jta-1.1.jar" /> <pathelement location="lib/postgres/postgresql-9.1-901.jdbc4.jar" /> <pathelement location="lib/spring/org.springframework.transaction-3.0.6.RELEASE.jar" /> <pathelement location="lib/hibernate/dom4j-1.6.1.jar" /> <pathelement location="lib/slf4j/slf4j-api-1.6.1.jar" /> <pathelement location="lib/slf4j/slf4j-nop-1.6.1.jar" /> </path>
Building both the application and the JUnit tests.
<target name="build-project" depends="init"> <echo message="${ant.project.name}: ${ant.file}" /> <javac debug="true" debuglevel="${debuglevel}" destdir="build/classes" source="${source}" target="${target}" includeantruntime="false"> <src path="src" /> <classpath refid="myapplication.classpath" /> </javac> <javac debug="true" debuglevel="${debuglevel}" destdir="build/classes" source="${source}" target="${target}" includeantruntime="false"> <src path="test" /> <classpath refid="myapplication.classpath" /> </javac> </target>
Building the JUnit report. This turns up as a subdirectory with index.html you can browse. Builds one actual test, named AccountManagerTest.
<property name="junit.output.dir" value="junit" /> ... <target name="AccountManagerTest"> <mkdir dir="${junit.output.dir}"/> <junit fork="yes" printsummary="withOutAndErr"> <formatter type="xml"/> <test name="com.acme.web.user.manager.AccountManagerTest" todir="${junit.output.dir}"/> <classpath refid="rest-server.classpath"/> </junit> </target> ... <target name="junitreport"> <junitreport todir="${junit.output.dir}"> <fileset dir="${junit.output.dir}"> <include name="TEST-*.xml" /> </fileset> <report format="frames" todir="${junit.output.dir}" /> </junitreport> </target>