I created an ant build file to compile my java src into a .jar file. It uses external jar files.
My files dir:
+src
----android
------------Address.java
------------HelloServer.java
------------HelloServerResource.java
+lib
------------org.codehaus.jackson.core.jar
------------org.codehaus.jackson.mapper.jar
------------org.json.jar
------------org.restlet.ext.jackson.jar
------------org.restlet.jar
build.xml
The external libraries are in lib folder.
The main class is in HelloServer.java
Here is my ant build file:
<project name="helloworld">
<property name="src-dir" location="src"/>
<property name="build-dir" location="build"/>
<property name="classes-dir" value="${build-dir}/classes"/>
<property name="dist-dir" location="dist"/>
<property name="lib-dir" value="lib"/>
<property name="jar-dir" value="${build-dir}/jar"/>
<property name="main-class" value="android.HelloServer"/>
<path id="classpath">
<fileset dir="${lib-dir}" includes="**/*.jar"/>
</path>
<target name="clean" description="compile the source">
<delete dir="${build-dir}" />
<delete dir="${dist-dir}" />
</target>
<target name="cleanall" depends="clean"/>
<target name="init">
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build-dir}"/>
<mkdir dir="${classes-dir}"/>
<mkdir dir="${jar-dir}"/>
<!--<mkdir dir="${dist-dir}"/>-->
</target>
<target name="compile" depends="init" description="compile the source " >
<javac srcdir="${src-dir}" destdir="${classes-dir}" classpathref="classpath" includeantruntime="false" />
<!--<javac srcdir="${src-dir}" destdir="${build-dir}"/>-->
</target>
<target name="jar" depends="compile">
<jar destfile="${jar-dir}/${ant.project.name}.jar" basedir="${classes-dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path location="${jar-dir}/${ant.project.name}.jar"/>
</classpath>
</java>
</target>
</project>
I execute run and all the dirs were created successfully, the .jar file was created and it was able to be executed.
I open terminal and go to the jar dir. I tried to execute through command line like this and it gave me the following error:
$java -jar helloworld.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/restlet/Server
at android.HelloServer.main(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.restlet.Server
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 1 more
Why does it say class file not found? I thought by creating the helloworld jar file, i actually included the external libraries.
You'll need to combine all the jars together using zipgroupfileset:
<target name="jar" depends="compile">
<jar destfile="${jar-dir}/${ant.project.name}.jar" basedir="${classes-dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
<zipgroupfileset dir="${lib-dir}" includes="*.jar"/>
</jar>
</target>
See: Creating a bundle jar with ant
i found a solution. basically i compile my jar file and point it to the external jar files using manifest file.
here is my build file:
<project name="helloworld">
<property name="src-dir" location="src"/>
<property name="build-dir" location="build"/>
<property name="classes-dir" value="${build-dir}/classes"/>
<property name="dist-dir" location="dist"/>
<property name="lib-dir" value="lib"/>
<property name="jar-dir" value="${build-dir}/jar"/>
<property name="main-class" value="android.HelloServer"/>
<path id="classpath">
<fileset dir="${lib-dir}" includes="**/*.jar"/>
</path>
<target name="clean" description="compile the source">
<delete dir="${build-dir}" />
<delete dir="${dist-dir}" />
</target>
<target name="cleanall" depends="clean"/>
<target name="init">
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build-dir}"/>
<mkdir dir="${classes-dir}"/>
<mkdir dir="${jar-dir}"/>
<!--<mkdir dir="${dist-dir}"/>-->
</target>
<target name="compile" depends="init" description="compile the source " >
<javac srcdir="${src-dir}" destdir="${classes-dir}"
classpathref="classpath" includeantruntime="false" />
<!--<javac srcdir="${src-dir}" destdir="${build-dir}"/>-->
</target>
<target name="jar" depends="compile">
<manifestclasspath property="jar.classpath" jarfile="${jar-dir}/${ant.project.name}.jar">
<classpath refid="classpath"/>
</manifestclasspath>
<jar destfile="${jar-dir}/${ant.project.name}.jar" basedir="${classes-dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
<attribute name="Class-Path" value="${jar.classpath}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path location="${jar-dir}/${ant.project.name}.jar"/>
</classpath>
</java>
</target>
</project>
The main difference is that i added the following into targer "jar":
<manifestclasspath property="jar.classpath" jarfile="${jar-dir}/${ant.project.name}.jar">
<classpath refid="classpath"/>
</manifestclasspath>
<attribute name="Class-Path" value="${jar.classpath}"/>
Related
According to the training task, I need to create .jar-file with ant. There are no problems with the Assembly of ordinary classes that are in src .
But I have in project present logger, libraries to him and .properties file.
because of this, errors fly out:
[javac] error: package org.apache.logging.log4j does not exist
and
error: cannot find symbol
[javac] error: private static final Logger logger = LogManager.getLogger(Hello.class);
I have build.xml
<?xml version="1.0"?>
<project name="Runner" default="run">
<!-- define names of directories -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="classes" location="${build}/classes"/>
<!-- define all targets -->
<target name="compile">
<mkdir dir="${classes}"/>
<javac srcdir="${src}" destdir="${classes}" includeAntRuntime="false"/>
</target>
<target name="run" depends="compile">
<java classname="${ant.project.name}" classpath="${classes}"/>
</target>
<target name="clean">
<delete dir="${build}"/>
</target>
<target name="package" depends="compile">
<jar destfile="${build}/${ant.project.name}.jar" basedir="${classes}">
<manifest>
<attribute name="Main–Class" value="${ant.project.name}"/>
</manifest>
</jar>
</target>
</project>
and this stracture
How and where to gather library and property in Java file to jar-file was executable?
I figured it out.
<path id="classpath">
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="init" depends="clean" description="starts">
<tstamp/>
</target>
<target name="clean" depends="package-to-jar" description="clean up">
<delete dir="${classes}"/>
<delete file="${external-lib}"/>
</target>
<target name="package-to-jar" depends="package-external-lib" description="packing all project into a jar-file">
<jar destfile="${jar}/${ant.project.name}.jar" basedir="${classes}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
<zipfileset src="${external-lib}"/>
</jar>
<delete dir="${classes}"/>
<delete file="${external-lib}"/>
</target>
<target name="package-external-lib" depends="compile" description="packing external libraries into a jar-file">
<jar destfile="${external-lib}">
<zipgroupfileset dir="${lib}">
<include name="**/*.jar"/>
</zipgroupfileset>
</jar>
</target>
<target name="compile" description="compile the source">
<mkdir dir="${classes}"/>
<javac srcdir="${src}" destdir="${classes}" classpathref="classpath"/>
<copy todir="${classes}">
<fileset dir="${src}" excludes="**/*.java"/>
</copy>
</target>
Firstly you need include required library folders to class path
<path id="class.path">
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</path>
and add reference to javac task in compile target
<target name="compile">
<mkdir dir="${classes}"/>
<javac srcdir="${src}" destdir="${classes}" includeAntRuntime="false">
<classpath refid="class.path" />
</javac>
</target>
aftewards include all properties file to jar
<target name="package" depends="compile">
<jar destfile="${build}/${ant.project.name}.jar" basedir="${classes}">
<include name="*.properties"/>
<manifest>
<attribute name="Main–Class" value="${ant.project.name}"/>
</manifest>
</jar>
</target>
I've been trying to follow this tutorial over at http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html.
I've got to the part entitled using external libraries, and I was trying to use the log4j2 libraries. When I do ant clean and ant compile jar run in terminal, it launches just fine, however, if I go to the the build/jar folder in my filesystem and double click the jar file, it doesn't open.
Currently, my build file looks like this:
<project name="HelloWorld" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="hlw.HelloWorld"/>
<property name="lib.dir" value="lib"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" includeantruntime="false"/>
<copy todir="${classes.dir}">
<fileset dir="${src.dir}" excludes="**/*.java"/>
</copy>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
<attribute name="Class-Path" value="config/ properties/ ${manifest.classpath}" />
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>
</java>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
<target name="test" depends="jar">
<junit printsummary="yes">
<classpath>
<path refid="classpath"/>
<path refid="application"/>
</classpath>
<batchtest fork="yes">
<fileset dir="${src.dir}" includes="*Test.java"/>
</batchtest>
</junit>
</target>
Is there something wrong with this build file that prevents the jar from working when being double clicked?
Edit: when typing jar -jar HelloWorld.jar in Terminal I get the following response:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
at hlw.HelloWorld.<clinit>(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
When running your application from ant, you explicitly add jars from lib/ directory to your class-path. When running the jar directly, java has no way of knowing where those jars are.
The simplest way to fix this is to bundle all those dependencies inside single jar:
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<zipgroupfileset dir="${lib.dir}" includes="**/*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
<attribute name="Class-Path" value="config/ properties/ ${manifest.classpath}" />
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java fork="true" jar="${jar.dir}/${ant.project.name}.jar" />
</target>
If you don't want to repackage those libraries, you can add paths to them in your manifest:
https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
Hi I'm working on a project where i'm told to create dist ant target which creates JAR file and jrun target which depends on dist target ant should run dist created jar file. While ant jrun i get the folowing error : jrun
[java]: no main manifest attribute in *\build\jar\navus.jar
<?xml version="1.0" encoding="UTF-8"?>
<project name="POS" default="build" basedir=".">
<!-- Project properties-->
<property name="src.dir" value="${basedir}/src"/>
<property name="build.dir" value="${basedir}/build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main.class" value="ee.ut.math.tvt.navus.Intro"/>
<!-- Different classpaths form compiling and running-->
<path id="compile.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="run.classpath">
<pathelement location="${classes.dir}"/>
<path refid="compile.classpath"/>
</path>
<!-- Clean existing build-->
<target name="clean">
<delete dir="${build.dir}" />
</target>
<!-- Builds Java code-->
<target name="build" depends="clean">
<mkdir dir="${build.dir}"/>
<mkdir dir="${classes.dir}"/>
<copy file="${src.dir}/log4j.properties" todir="${classes.dir}" overwrite="true" />
<javac
srcdir="${src.dir}"
destdir="${classes.dir}">
<classpath refid="compile.classpath"/>
</javac>
</target>
<!-- Creates jar file-->
<target name="dist" depends="build">
<mkdir dir="${jar.dir}"/>
<propertyfile file="version.properties">
<entry key="build.revision.number" type="int" default="0" operation="+"/>
</propertyfile>
<jar jarfile="${build.dir}/jar/navus.jar"
basedir="${build.dir}/classes">
<manifest>
<attribute name="mainClass" value="${main.class}"/>
</manifest>
<fileset dir="${basedir}" includes="${src.dir}"/>
</jar>
</target>
<!-- Executes application via class Intro-->
<target name="run" depends="build"
description="runs introUI via Intro" >
<java classname="${main.class}"
classpathref="run.classpath"
fork="yes">
</java>
</target>
<!-- Runs application using JAR file-->
<target name="jrun" depends="dist"
description=" Run JAR file">
<java jar="${jar.dir}/navus.jar"
fork="yes"/>
</target>
</project>
Looking at google returns https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html. Maybe try something like this -
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="oata.HelloWorld"/>
</manifest>
</jar>
</target>
You need to create a manifest file (MANIFEST.MF), which goes inside the META-INF folder inside your jar. It resembles this:
Manifest-Version: 1.0
Application-Name: MyApp
Sealed: true
Main-Class: com.mysite.myappname.myMainClass
Codebase: www.mysite.com
My Eclipse project has the following structure:
-- | My project
|-src
|-build
|-doc
|-lib
In lib are placed my jar files. These files have been added to the Build path with "Add to Buildpath command". The project successfully compiles.
I want to build the project with Ant, to this aim I wrote the following xml file
<project name="ABTestConnector" basedir=".">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="test.Prova"/>
<property name="lib.dir" value="/lib"/>
<property name="doc.dir" value="/doc"/>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<path id="class-path">
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</path>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}">
<classpath refid="class-path"/>
</javac>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
<fileset dir="${classes.dir}" includes="**/*.class" />
<zipgroupfileset dir="${lib.dir}" includes="**/*.jar" />
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
<target name="doc" depends="clean-build" description="generate javadoc">
<javadoc sourcepath="${src.dir}" destdir="${doc.dir}"/>
</target>
I have also tried in the fileset: include name="**/*.jar"/>
But I still get the errors
[javac] /home/bruno/Documenti/TestingEnvironment/EclipseWorkspace/SeleniumABTestConnector_0.0.1/src/driversTod/TodSelenium.java:10: package org.openqa.selenium does not exist
[javac] import org.openqa.selenium.By;
Thank you in advance.
I'm using the Hello World with Ant tutorial from the Ant manual to learn about Ant.
The last part of the tutorial involves adding JUnit tests to the project.
I've got everything working as described in the tutorial and am now going on to make some minor changes.
One of the changes I would like to make is to run the tests during a typical build but not have the *Test.class files end up in the final .jar file for the application. This is because the eventual project I will be working on will be for a device with limited hard drive space and support for only a subset of the Java SDK so I would prefer to just omit these test files entirely from the jar.
How do I do this?
It would be easy enough to create two separate jars, one for testing and one for deployment, but this seems less than ideal.
My current build.xml file is below.
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="lib.dir" value="lib"/>
<property name="report.dir" value="${build.dir}/junitreport"/>
<property name="main-class" value="oata.HelloWorld"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
<path location="[LocalPath]/junit-4.8.2.jar"/>
</path>
<path id="application" location="${jar.dir}/${ant.project.name}.jar"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
<copy todir="${classes.dir}">
<fileset dir="${src.dir}" excludes="**/*.java"/>
</copy>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="junit" depends="jar">
<mkdir dir="${report.dir}"/>
<junit printsummary="yes" haltonfailure="yes" showoutput="yes">
<classpath>
<path refid="classpath"/>
<path refid="application"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="yes">
<fileset dir="${src.dir}" includes="*Test.java"/>
</batchtest>
</junit>
</target>
<target name="junitreport" depends="junit">
<junitreport todir="${report.dir}">
<fileset dir="${report.dir}" includes="TEST-*.xml"/>
<report todir="${report.dir}"/>
</junitreport>
</target>
<target name="run" depends="junit">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path refid="application"/>
</classpath>
</java>
</target>
<target name="clean-build" depends="clean,junit"/>
<target name="main" depends="clean,run"/>
One thing I have tried is modifying the jar command to exclude the *Test.class files
...
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" excludes="**/*Test.class">
...
which successfully excludes the test classes but then when the tests are run via the junit target it fails with the following stack trace when run with -v:
[LocalPath]\build.xml:44: Test HelloWorldTest failed
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.actOnTestResult(JUnitTask.java:1863)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:814)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1808)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:760)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1397)
at org.apache.tools.ant.Project.executeTarget(Project.java:1366)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1249)
at org.apache.tools.ant.Main.runBuild(Main.java:801)
at org.apache.tools.ant.Main.startAnt(Main.java:218)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Can you change:
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
to:
<target name="jar" depends="junit">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar">
<fileset dir="${classes.dir}" excludes="**/*Test.class"/>
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="junit" depends="compile">
<mkdir dir="${report.dir}"/>
<junit printsummary="yes" haltonfailure="yes" showoutput="yes">
<classpath>
<path refid="classpath"/>
<path refid="application"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="yes">
<fileset dir="${src.dir}" includes="*Test.java"/>
</batchtest>
</junit>
</target>
That should exclude the Test classes I believe from the final JAR file.
n.b The change in dependencies for each of the tasks.
Based on #Jon's advice I changed the junit target to run against the build/classes folder instead of the jar and updated the dependencies appropriately.
My updated build.xml file is below:
<project name="HelloWorld" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="lib.dir" value="lib"/>
<property name="report.dir" value="${build.dir}/junitreport"/>
<property name="main-class" value="oata.HelloWorld"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
<path location="[LocalPath]/junit-4.8.2.jar"/>
</path>
<path id="application" location="${jar.dir}/${ant.project.name}.jar"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
<copy todir="${classes.dir}">
<fileset dir="${src.dir}" excludes="**/*.java"/>
</copy>
</target>
<target name="jar" depends="junit">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" excludes="**/*Test.class">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="junit" depends="compile">
<mkdir dir="${report.dir}"/>
<junit printsummary="yes" haltonfailure="yes" showoutput="yes">
<classpath>
<path refid="classpath"/>
<path location="${classes.dir}"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="yes">
<fileset dir="${src.dir}" includes="*Test.java"/>
</batchtest>
</junit>
</target>
<target name="junitreport" depends="junit">
<junitreport todir="${report.dir}">
<fileset dir="${report.dir}" includes="TEST-*.xml"/>
<report todir="${report.dir}"/>
</junitreport>
</target>
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path refid="application"/>
</classpath>
</java>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
</project>