Wednesday, July 24, 2013

Get started with Apache Ant

build.xml


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="RunApp" 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="RunApp-Class" value="x.y.z.RunApp" />
<property name="lib.dir" value="lib" />

 <!-- set the classpath that includes jar -->
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</path>

<!-- All Ant targets begin here -->
<!--Notes includeantruntime: Whether to include the Ant run-time libraries
in the classpath; defaults to yes, unless build.sysclasspath is set. It is
usually best to set this to false so the script's behavior is not sensitive
to the environment in which it is run -->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${jar.dir}" />
<delete dir="${classes.dir}" />
</target>

<target name="compile">
<mkdir dir="${classes.dir}" />
<copy todir="${classes.dir}">
<fileset dir="${src.dir}" excludes="**/*.java" />
</copy>
<javac srcdir="${src.dir}" includeantruntime="false"
                 destdir="${classes.dir}"
classpathref="classpath" />
</target>

<target name="jar">
     <mkdir dir="${jar.dir}" />
     <jar destfile="${jar.dir}/${ant.project.name}.jar"
            basedir="${classes.dir}">
          <manifest>
                 <attribute name="RunApp-Class"
                                value="{RunApp-Class}" />
         </manifest>
     </jar>
</target>

<target name="run" depends="jar">
<java fork="true" classname="${RunApp-Class}">
<classpath>
<path refid="classpath" />
<path location="${jar.dir}/${ant.project.name}.jar" />
</classpath>
</java>
</target>

</project>

   

No comments:

Post a Comment