Ant build file to compile and clean resources

Hi,
Below is a example for showing how to compile ,clean and make jar file of a project.
Here i have given just a brief introduction of the tags how to use them. Advance build file structure i will include in coming post.
Example:


<?xml version="1.0"?>
<project name="classroom" basedir=".">
<property name="projectname" value="classroom" />
<property name="srcprop.dir" value="conf" />
<property name="build.dir" value="./compiled" />
<property name="src.dir" value="src">
</property>


<target name="usage">
<echo message="------------" />
<echo message="Building ${projectname} project..." />
</target>

<!--Create  directory -->
<target name="init">
<mkdir dir="${build.dir}" />
<echo message="Compiled Directory created" />
</target>

<!--
           Compile the java classes.This target will compile our classes inside 
           "src" folder and its sub-directories also .So here i have mentioned 
            source directory and destination directory ("build.dir").
       -->
<target name="build" depends="init">
<javac destdir="${build.dir}" target="1.5" failonerror="true">
<src path="${src.dir}" />
</javac>
</target>

<!--
            Create jar file.Now this target is responsible for creating jar file.
            It has to be informed  from where  it has to pick the compiled classes 
            ,so inside fileset i have defined "buid.dir" 
        -->
<target name="createjar">
<jar destfile="classroom.jar">
<fileset dir="${build.dir}"/>
</jar>
</target>


<!-- 
            Clean up resources.This target will just delete our folder "build.dir".
         -->
<target name="cleanup" depends="init">
<delete dir="${build.dir}"/>
</target>

</project>


Above targets are being given just to give a basic idea about them.You can put more conditions inside the targets and run in your own way...
:)



Comments

Popular posts from this blog

Arrays.sort() and Collections.sort() NullPointerException

org.xml.sax. SAXParseException: Element type "web-app" must be declared.

Sentimental Analysis : PART 1