Search This Blog

Tuesday, January 5, 2016

Create ant build on a demo project

Download ant zip from apache.org

Create a project - with java code in src directory
put the below xml as build.xml in same directory.

Run the ant from command line as 
>ant compile jar run

if you want to specify a special build file you can do so with 

> ant -buildfile build.xml compile jar run

<project>


   <target name="clean">
       <delete dir="build"/>
   </target>


   <target name="compile">
       <mkdir dir="build/classes"/>
       <javac srcdir="src" destdir="build/classes"/>
   </target>


   <target name="jar">
       <mkdir dir="build/jar"/>
       <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
           <manifest>
               <attribute name="Main-Class" value="javatest.JavaTest"/>
           </manifest>
       </jar>
   </target>


   <target name="run">
       <java jar="build/jar/HelloWorld.jar" fork="true"/>
   </target>

</project>

No comments:

Post a Comment