11
Tutorial For ANT Build Files How to write a simple ANT build files for the Enterprise projects. 08/27/2022 Ravi Reddy (Ravinder Nancherla) 1

Tutorial to develop build files using ANT

Embed Size (px)

DESCRIPTION

Tutorial to develop build files using ANT

Citation preview

Page 1: Tutorial to develop build files using ANT

04/08/2023 Ravi Reddy (Ravinder Nancherla) 1

Tutorial For ANT Build FilesHow to write a simple ANT build files for the Enterprise

projects.

Page 2: Tutorial to develop build files using ANT

04/08/2023 Ravi Reddy (Ravinder Nancherla) 2

ANT Tutorials Tutorials How to write a build file for a simple Java project Create a simple sample project in your eclipse IDE, Below is the screen shot and build script.

Page 3: Tutorial to develop build files using ANT

04/08/2023 Ravi Reddy (Ravinder Nancherla) 3

ANT Tutorials Build.xml

<project name="TestAnt" basedir="." default="run">

<!-- Clean Target --><target name="clean"><delete dir="build"/></target>

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

<!-- Make JAR Target --><target name="jar"><mkdir dir="build/jar"/><jar destfile="build/jar/TestAnt.jar" basedir="build/classes"><manifest><attribute name="Main-Class" value="com.test.ant.EmployeeTestClient"/></manifest></jar></target>

<!-- Run JAR to execute the main class. --><target name="run"><java jar="build/jar/TestAnt.jar" fork="true"/></target>

</project>

Page 4: Tutorial to develop build files using ANT

04/08/2023 Ravi Reddy (Ravinder Nancherla) 4

ANT Tutorials Tutorials How to write a build file for a simple Java Web

projectCreate a simple sample web project in your eclipse IDE, Below is the screen shot and build script.

Page 5: Tutorial to develop build files using ANT

04/08/2023 Ravi Reddy (Ravinder Nancherla) 5

ANT Tutorials Build.xml

<?xml version="1.0"?><project name="AntTestForWebApp" default="buildWar" basedir=".">

<property name="baseDir" value="${basedir}" /><property name="src" value="${baseDir}/src" /><property name="webRoot" value="${baseDir}/WebRoot" /><property name="warDir" value="${baseDir}/build/war" /><property name="libDir" value="${warDir}/WEB-INF/lib" />

<path id="libClasspath"><fileset dir="${webRoot}/WEB-INF/lib" includes="**/*.jar" />

</path>

<!-- ========================= **** Clean Target **** =========================--><target name="clean">

<delete dir="${baseDir}/build" /></target>

<!-- ========================= **** Init Target **** =========================--><target name="init">

<!-- Create Web-INF,lib, classes, META-INF directories --><mkdir dir="${libDir}" /><mkdir dir="${warDir}/WEB-INF" /><mkdir dir="${warDir}/WEB-INF/classes" /><mkdir dir="${warDir}/META-INF" />

</target>

Page 6: Tutorial to develop build files using ANT

04/08/2023 Ravi Reddy (Ravinder Nancherla) 6

ANT Tutorials<!-- =================== **** COMPILE **** =======================================

Compile Java Files and place the following things in 1) *.classes files in WEB-INF/classes 2) *.jar files in WEB-INF/lib 3) web.xml in WEB-INF 4) *.jsp files in parent directory path build/war

================================================================================ --><target name="compile" depends="init">

<javac srcdir="${src}" destdir="${warDir}/WEB-INF/classes" debug="true" includes="**/*.java" optimize="on">

<classpath refid="libClasspath" /></javac><copy todir="${libDir}">

<fileset dir="${webRoot}/WEB-INF/lib" includes="**/*.jar" /></copy><copy todir="${warDir}/WEB-INF">

<fileset dir="${webRoot}/WEB-INF" includes="web.xml" /></copy><copy todir="${warDir}">

<fileset dir="${webRoot}" includes="*.jsp" /></copy>

</target>

Page 7: Tutorial to develop build files using ANT

04/08/2023 Ravi Reddy (Ravinder Nancherla) 7

ANT Tutorials<!-- ========================= **** Create the WAR File **** =========================--><target name="buildWar">

<!-- Option 1: Using <jar> create war file and place WAR file in BUILD directory --><!-- <jar jarfile="${baseDir}/build/AntTestForWebApp.war" basedir="${warDir}" />

-->

<!-- Option 2: Using <war> create war file and place WAR file in BUILD directory --><war destfile="${baseDir}/build/AntTestForWebApp.war" webxml="${warDir}/WEB-INF/web.xml">

<zipfileset dir="${warDir}"/> </war>

</target>

</project>

Page 8: Tutorial to develop build files using ANT

04/08/2023 Ravi Reddy (Ravinder Nancherla) 8

ANT Tutorials Tutorials How to write a build file for a simple Java Web

projectCreate a simple sample EAR project in your eclipse IDE, Below is the screen shot and build script.

Page 9: Tutorial to develop build files using ANT

04/08/2023 Ravi Reddy (Ravinder Nancherla) 9

ANT Tutorials<?xml version = "1.0" encoding = "UTF-8"?><!-- ==========================================================================--><!-- Trying Build file for EAR Application --><!-- build.xml, Friday, August 27, 2010 --><!-- Author: Ravinder Nancherla --><!-- Email: [email protected] --><!-- Copyright(c) 2010 Ravinder Nancherla (Ravi Reddy)., All Rights Reserved. --><!-- ========================================================================= -->

<project name="AntEarWarJar" default="buildEar" basedir=".">

<property name="webModule" value="C:/SravanthiPractice/AntEarWarJarWeb"/><property name="ejbModule" value="C:/SravanthiPractice/AntEarWarJarEJB"/><property name="baseDir" value="${basedir}"/><property name="build" value="${baseDir}/build"/>

<property name="jarDir" value="${baseDir}/build/jar"/><property name="warDir" value="${baseDir}/build/war"/><property name="earDir" value="${baseDir}/build/ear"/>

<property name="webRootDir" value="${webModule}/WebRoot/WEB-INF"/><property name="webDir" value="${warDir}/WEB-INF"/>

<path id="libClasspath"><fileset dir="${webRootDir}/lib" includes="**/*.jar" /></path>

Page 10: Tutorial to develop build files using ANT

04/08/2023 Ravi Reddy (Ravinder Nancherla) 10

ANT Tutorials<!-- Cleaning the build directory --><target name="clean"><delete dir="${build}"/></target>

<!-- Initializing/Creating the directories --> <target name="init" depends="clean"><mkdir dir="${jarDir}/classes"/><mkdir dir="${jarDir}/jar"/><mkdir dir="${warDir}/META-INF"/><mkdir dir="${webDir}/classes"/><mkdir dir="${webDir}/lib"/><mkdir dir="${earDir}/META-INF"/></target>

<!-- Compiling and copying the files from EjbModule and WebModiule --><target name="compile" depends="init"><javac srcdir="${ejbModule}/src" destdir="${jarDir}/classes" includes="**/*.java"/><javac srcdir="${webModule}/src" destdir="${webDir}/classes" includes="**/*.java">

<classpath refid="libClasspath"/></javac>

<copy todir="${webDir}/lib"><fileset dir="${webRootDir}/lib" includes="**/*.jar"/>

</copy>

Page 11: Tutorial to develop build files using ANT

04/08/2023 Ravi Reddy (Ravinder Nancherla) 11

ANT Tutorials<copy todir="${webDir}">

<fileset dir="${webRootDir}" includes="web.xml"/></copy><copy todir="${warDir}">

<fileset dir="${webModule}/WebRoot" includes="**/*.jsp"/></copy><copy todir="${earDir}/META-INF">

<fileset dir="${baseDir}/META-INF" includes="**/*.*"/></copy></target>

<!-- Creating Jar File --><target name="buildJar" depends="compile"><jar jarfile="${earDir}/${ant.project.name}.jar" basedir="${jarDir}"/><jar jarfile="${jarDir}/jar/${ant.project.name}.jar" basedir="${jarDir}"/></target>

<!-- Creating War File --><target name="buildWar" depends="compile"><jar jarfile="${earDir}/${ant.project.name}.war" basedir="${warDir}"/></target><!-- Creating Ear File --><target name="buildEar" depends="buildJar,buildWar"><jar jarfile="${build}/${ant.project.name}.ear" basedir="${earDir}"/></target></project>