> Ant allows the developer to automate the repeated process involved in the development of J2EE application.
> Developers can easily write the script to automate the build process like compilation, archiving and deployment.
> Downloading and Installing Ant
> Set the class path to the bin directory of the ant.
Let's assume that Ant is installed in c:\ant\. The following code has to be put into autoexec.bat file:
set ANT_HOME=c:\ant
set JAVA_HOME=c:\Program Files\Java\jdk1.6.0\
set PATH=%PATH%;%ANT_HOME%\bin
Testing Ant
Go to command prompt and issue the following command.
C:\anttest>Ant
Buildfile: build.xml does not exist!Build failed
C:\anttest>
If every this is installed correctly Ant will give the above message.
Now its time to do some work with Ant.
Ant uses configuration file called build.xml to work. This is the file where you defines the process of compiling, building and deploying.
Writing build.xml file
build.xml is a xml file used by ant utility to compile, build and deploy or run the application.
Now here is code of simple build.xml file which compiles a java file present in src directory and places compiled class file in build/src directory.
<?xml version="1.0"?>
<!-- Build file for our first application -->
< project name="Ant test project" default="build" basedir=".">
< target name="build" >
< javac srcdir="src" destdir="build/src" debug="true"
includes="**/*.java"
/>
</target>
</project>
-------------------------------------------------------------------------
The project tag:
requires three attributes namely name, default and basedir.
Here is the description of the attributes:
name |Represents the name of the project.
----------------------------------------------------
default |Name of the default target to use when no target is supplied.
basedir |Name of the base directory from which all path calculations are done.
All the attributes are required.
—-build1.xml ——–
< project name=”hello” default=”hello”>
< target name=”hello”>
< echo message=”Hello, World”/>
</target>
< target name=”goodbye”>
< echo message=”Goodbye, end of Hello world script”/>
< /target>
< /project>
No comments:
Post a Comment