This discussion is archived
0 Replies Latest reply: May 20, 2012 11:32 PM by 937323 RSS

How to create a jar from a java project in the file system Using ANT tool

937323 Newbie
Currently Being Moderated
I have a java project in a local system and i am trying to create an automate "jar" file . The project contains main folder with sub-folders .Just tell me how build.xml is created for building a jar.

Build.XML


<project name="MCMPCoreEngine" basedir="." default="main">

<property name="src.dir" value="src"/>
<property name="external.lib.dir" value="lib"/>
<property name="external.lib" value="${external.lib.dir}/DCFJars"/>
<property name="external.jar" value="${external.lib.dir}/ThunderheadJars"/>

<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>


<path id="mcmpcoreengine.classpath">
<fileset dir="${external.lib.dir}"/>
<fileset dir="${external.lib}"/>
<fileset dir="${external.jar}"/>
<include name="*.jar"/>
</path>



<target name="clean">
<delete dir="${build.dir}"/>
</target>

<target name="compile">
<mkdir dir="${classes.dir}"/>


<javac srcdir="${src.dir}" destdir="${classes.dir}">
<classpath refid="mcmpcoreengine.classpath"/>
</javac>

</target>

<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/MCMPCoreEngine.jar" basedir="${classes.dir}">

</jar>
</target>

<target name="run" depends="jar">
<java jar="${jar.dir}/MCMPCoreEngine.jar" fork="true"/>
</target>

<target name="clean-build" depends="clean,jar"/>

<target name="main" depends="clean,run"/>

</project>

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points