Firstly download ant package from Apache site.
http://ant.apache.org/antlibs/bindownload.cgi
After downloading the ant package extract the package and follow below metioned steps:-
How to set Environment variable in linux
Create a file with name of ant_file.sh in directory (i.e. /etc/profile.d/ )
vi /etc/profile.d/ant_file.sh
Add the following contents:
#!/bin/bash
ANT_HOME=/opt/ant
PATH=$ANT_HOME/bin:$PATH
export PATH ANT_HOME
export CLASSPATH=.
Save and close the file. (:wq!)
#> chmod +x /etc/profile.d/ant_file.sh
Set environment variables permanently by running the following command:
#> source /etc/profile.d/ant_file.sh
Now, check the ant install with ant version using command:
#> ant -version
Example of Ant:-
<project name="JSD" default="war" basedir=".">
<description>
jsd education War file
</description>
<!-- set global properties for this build -->
<property environment="env"/>
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="lib.dir" value="WebContent/WEB-INF/lib"/>
<path id="compile.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="init" depends="clean">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}/classes"/>
</target>
<target name="compile" depends="init" description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<path id="lib.path.ref">
<fileset dir="" includes="*.jar"/>
</path>
<javac srcdir="${src}" destdir="build/classes">
<classpath refid="compile.classpath"/>
</javac>
<copy todir="build/classes" flatten="no">
<fileset dir="${src}">
<include name="**/*.xml"/>
</fileset>
</copy>
</target>
<target name="war" depends="compile" description="generate the distribution" >
<!-- Create the distribution directory -->
<copy todir="build/classes" flatten="no">
<fileset dir="${src}">
<include name="/com/jsd/education/db/dao/hbm/*.xml"/>
</fileset>
</copy>
<war destfile="${build}/JSD.war" webxml="WebContent/WEB-INF/web.xml">
<classes dir="build/classes"/>
<fileset dir="WebContent">
<exclude name="**/*.jar"/>
</fileset>
<exclude name="${lib.dir}/*.jar"/>
</war>
<delete dir="${build}/classes"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
</target>
</project>
http://ant.apache.org/antlibs/bindownload.cgi
After downloading the ant package extract the package and follow below metioned steps:-
How to set Environment variable in linux
Create a file with name of ant_file.sh in directory (i.e. /etc/profile.d/ )
vi /etc/profile.d/ant_file.sh
Add the following contents:
#!/bin/bash
ANT_HOME=/opt/ant
PATH=$ANT_HOME/bin:$PATH
export PATH ANT_HOME
export CLASSPATH=.
Save and close the file. (:wq!)
#> chmod +x /etc/profile.d/ant_file.sh
Set environment variables permanently by running the following command:
#> source /etc/profile.d/ant_file.sh
Now, check the ant install with ant version using command:
#> ant -version
<project name="JSD" default="war" basedir=".">
<description>
jsd education War file
</description>
<!-- set global properties for this build -->
<property environment="env"/>
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="lib.dir" value="WebContent/WEB-INF/lib"/>
<path id="compile.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="init" depends="clean">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}/classes"/>
</target>
<target name="compile" depends="init" description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<path id="lib.path.ref">
<fileset dir="" includes="*.jar"/>
</path>
<javac srcdir="${src}" destdir="build/classes">
<classpath refid="compile.classpath"/>
</javac>
<copy todir="build/classes" flatten="no">
<fileset dir="${src}">
<include name="**/*.xml"/>
</fileset>
</copy>
</target>
<target name="war" depends="compile" description="generate the distribution" >
<!-- Create the distribution directory -->
<copy todir="build/classes" flatten="no">
<fileset dir="${src}">
<include name="/com/jsd/education/db/dao/hbm/*.xml"/>
</fileset>
</copy>
<war destfile="${build}/JSD.war" webxml="WebContent/WEB-INF/web.xml">
<classes dir="build/classes"/>
<fileset dir="WebContent">
<exclude name="**/*.jar"/>
</fileset>
<exclude name="${lib.dir}/*.jar"/>
</war>
<delete dir="${build}/classes"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
</target>
</project>
No comments:
Post a Comment