Ant build tool2

  • 201 views
Uploaded on

2/2 ANT build tool examples. See first part ANT introduction: http://www.slideshare.net/rohit4/ant-build-tool1

2/2 ANT build tool examples. See first part ANT introduction: http://www.slideshare.net/rohit4/ant-build-tool1

More in: Education , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
201
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/ant01.html 1/8Codin | Home | Previous | 01 | EndANT - Build Tool# ANT Example1:HelloWorld.javapackageco.rakshit;publicclassHelloWorld{publicstaticvoidmain(String[]args){System.out.println("WelcometoANT");}}build.xml<projectname="HelloWorld"default="run"><targetname="compile"><mkdirdir="co/rakshit"/><javacsrcdir="."destdir="."/><echo>Compilationisdone</echo></target><targetname="package"depends="compile"><jardestfile="HelloWorld.jar"basedir="."includes="co/rakshit/*.class"/></target><targetname="run"depends="package"><javaclassname="co.rakshit.HelloWorld"><classpath><pathelementlocation="."/></classpath></java><echo>Executionisdone</echo></target></project>Download this exampleDownload .jar files
  • 2. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/ant01.html 2/8# ANT Example2:Note: use the HelloWorld.java from previous examplebuild.xml<projectname="HelloWorld"default="run"><propertyname="classes.dir"value="build/classes"/><propertyname="target.dir"value="target"/><propertyname="project.name"value="HelloWorld"/><targetname="clean"><deletedir="${classes.dir}"/><deletedir="${target.dir}"/></target><targetname="init"depends="clean"><mkdirdir="${classes.dir}"/><mkdirdir="${target.dir}"/></target><targetname="compile"depends="init"><mkdirdir="${classes.dir}/co/rakshit"/><javacsrcdir="src"destdir="${classes.dir}"/><echo>Compilationisdone</echo></target><targetname="package"depends="compile"><jardestfile="${target.dir}/${project.name}.jar"basedir="${classes.dir}"/><echo>packageisdone</echo></target><targetname="run"depends="package"><javaclassname="co.rakshit.HelloWorld"><classpath><pathelementlocation="${target.dir}/${project.name}.jar"/></classpath></java><echo>Executionisdone</echo></target></project>Download this exampleDownload .jar files
  • 3. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/ant01.html 3/8# ANT Example3:Note: use the HelloWorld.java from previous examplebuild.xml<projectname="HelloWorld"default="run"><propertyfile="build.properties"/><targetname="clean"><deletedir="${classes.dir}"/><deletedir="${target.dir}"/></target><targetname="init"depends="clean"><mkdirdir="${classes.dir}"/><mkdirdir="${target.dir}"/></target><targetname="compile"depends="init"><mkdirdir="${classes.dir}/co/rakshit"/><javacsrcdir="src"destdir="${classes.dir}"/><echo>Compilationisdone</echo></target><targetname="package"depends="compile"><jardestfile="${target.dir}/${project.name}.jar"basedir="${classes.dir}"/><echo>packageisdone</echo></target><targetname="run"depends="package"><javaclassname="co.rakshit.HelloWorld"><classpath><pathelementlocation="${target.dir}/${project.name}.jar"/></classpath></java><echo>Executionisdone</echo></target></project>build.propertiesclasses.dir=build/classestarget.dir=targetproject.name=HelloWorld
  • 4. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/ant01.html 4/8Download this example# ANT Example4:Note: Before run below example, we need to copy servlet-api.jar file from tomcatinto our project "WEB-INFlib" folder.build.xml<projectname="WebANT"default="war"><propertyfile="build.properties"/><!--defineclasspathjars--><pathid="compile.classpath"><filesetdir="${web.lib.dir}"><includename="*.jar"/></fileset></path><targetname="init"depends="clean"><mkdirdir="${build.classes.dir}"/><mkdirdir="${dist.dir}"/></target><targetname="clean"><deletedir="${build.classes.dir}"/><deletedir="${dist.dir}"/></target><targetname="compile"depends="init"><javacsrcdir="src"destdir="${build.classes.dir}"><classpathrefid="compile.classpath"/></javac><echo>Compilationisdone</echo></target><targetname="war"depends="compile"><wardestfile="${dist.dir}/${project.name}.war"webxml="${web.dir}/WEB-INF/web.xml"><filesetdir="${web.dir}"/><libdir="${web.lib.dir}"/><classesdir="${build.classes.dir}"/></war><echo>packageisdone</echo></target>
  • 5. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/ant01.html 5/8</project>build.propertiesweb.dir=WebContentweb.lib.dir=${web.dir}/WEB-INF/libbuild.classes.dir=builds/classesdist.dir=distproject.name=LoginApplicationHelloWorld.javaimportjava.io.*;importjavax.servlet.*;publicclassHelloWorldextendsGenericServlet{publicvoidservice(ServletRequestreq,ServletResponseres)throwsServletException,IOException{res.setContentType("text/html");res.getWriter().print("<h1>HelloWorld</h1>");}}web.xml<web-app><servlet><servlet-name>hello</servlet-name><servlet-class>HelloWorld</servlet-class></servlet><servlet-mapping><servlet-name>hello</servlet-name><url-pattern>/hello</url-pattern></servlet-mapping></web-app>Download this example# ANT Example5:
  • 6. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/ant01.html 6/8Note: use HelloWorld.java, web.xml from previous example.Note: Before run below example, we need to copy servlet-api.jar and catalina-ant.jarfiles from tomcat into our project "WEB-INFlib" folder.Step 1: Tomcat Authentication-First add an user with adminstrator access right for Tomcat. To add Tomcat user, editthis file - "%TOMCAT_PATH%/conf/tomcat-users.xml".tomcat-users.xml<?xmlversion=1.0encoding=utf-8?><tomcat-users><rolerolename="manager"/><rolerolename="admin"/><userusername="admin"password="password"roles="admin,manager"/></tomcat-users>build.xml<projectname="LoginApplication"default="war"><propertyfile="build.properties"/><!--defineclasspathjars--><pathid="compile.classpath"><filesetdir="${web.lib.dir}"><includename="*.jar"/></fileset></path><targetname="init"depends="clean"><mkdirdir="${build.classes.dir}"/><mkdirdir="${dist.dir}"/></target><targetname="clean"><deletedir="${build.classes.dir}"/><deletedir="${dist.dir}"/></target>
  • 7. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/ant01.html 7/8<targetname="compile"depends="init"><javacsrcdir="src"destdir="${build.classes.dir}"><classpathrefid="compile.classpath"/></javac><echo>Compilationisdone</echo></target><targetname="war"depends="compile"><wardestfile="${dist.dir}/${project.name}.war"webxml="${web.dir}/WEB-INF/web.xml"><filesetdir="${web.dir}"/><libdir="${web.lib.dir}"/><classesdir="${build.classes.dir}"/></war><echo>packageisdone</echo></target><targetname="tomcat-start"depends="war"><javajar="${tomcat.home}/bin/bootstrap.jar"fork="true"><jvmargvalue="-Dcatalina.home=${tomcat.home}"/><argline="start"/></java></target><targetname="tomcat-stop"><javajar="${tomcat.home}/bin/bootstrap.jar"fork="true"><jvmargvalue="-Dcatalina.home=${tomcat.home}"/><argline="stop"/></java></target><targetname="deploy-tomcat"description="deploytotomcat"depends="tomcat-start"><echo>deployingfromclient</echo><deployurl="${tomcat-manager-url}"username="${tomcat-manager-username}"password="${tomcat-manager-password}"path="/${project.name}"war="file:./${dist.dir}/${project.name}.war"/><echo>Applicationsuccessfullydeployed</echo></target><targetname="undeploy"description="undeploying"><echo>undeployingfromclient</echo><undeployurl="${tomcat-manager-url}"username="${tomcat-manager-username}"password="${tomcat-manager-password}"path="/${project.name}"/></target><taskdefname="start"classname="org.apache.catalina.ant.StartTask"><classpath><pathelementlocation="${web.lib.dir}catalina-ant.jar"/></classpath></taskdef><taskdefname="stop"classname="org.apache.catalina.ant.StopTask"><classpath><pathelementlocation="${web.lib.dir}catalina-ant.jar"/></classpath>
  • 8. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/ant01.html 8/8</taskdef><taskdefname="deploy"classname="org.apache.catalina.ant.DeployTask"><classpath><pathelementlocation="${web.lib.dir}catalina-ant.jar"/></classpath></taskdef><taskdefname="undeploy"classname="org.apache.catalina.ant.UndeployTask"><classpath><pathelementlocation="${web.lib.dir}catalina-ant.jar"/></classpath></taskdef></project>build.propertiesweb.dir=WebContentweb.lib.dir=${web.dir}/WEB-INF/libbuild.classes.dir=builds/classesdist.dir=distproject.name=LoginApplicationtomcat.home=D:/dev/tomcat6tomcat-manager-url=http://localhost:8080/managertomcat-manager-username=rohittomcat-manager-password=rohitDownload this exampleCodin | Home | Previous | Index | End© Rohit Rakshit