Skip to content

Instantly share code, notes, and snippets.

@WA9ACE
Created November 25, 2012 21:34
Show Gist options
  • Save WA9ACE/4145482 to your computer and use it in GitHub Desktop.
Save WA9ACE/4145482 to your computer and use it in GitHub Desktop.
Example build.xml for projects.
<project name="FooBar" 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"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<property name="main-class" value="com.example.Foo.Bar"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="build">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
</target>
<target name="jar" depends="build">
<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="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"/>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment