Tutorials Navigation
Apache Ant Tutorial - Deploying Applications
Tutorial Name: Apache Ant Tutorial - Deploying Applications
Category: PC Tutorials
Submitted By: hoot
Date Added:
Comments: 0
Views: 347
Related Forum: PC Building Forum
Share:
In the previous chapter, we have learnt how to package an application and deploy it to a folder.
In this chapter, we are going to deploy the web application directly to the application server deploy folder, then we are going to add a few Ant targets to start and stop the services. Let us continue with the Hello World fax web application. This is a continuation of the previous chapter, the new components are highlighted in bold.
build.properties
# Ant properties for building the springapp
appserver.home = c:\install\apache-tomcat-7.0.19
# for Tomcat 5 use $appserver.home}/server/lib
# for Tomcat 6 use $appserver.home}/lib
appserver.lib = ${appserver.home}/lib
deploy.path = ${appserver.home}/webapps
tomcat.manager.url = example:8080/manager
tomcat.manager.username = example
tomcat.manager.password = secret
build.xml
<?xml version = "1.0"?>
<project name = "fax" basedir = "." default = "usage">
<property file = "build.properties"/>
<property name = "src.dir" value = "src"/>
<property name = "web.dir" value = "war"/>
<property name = "javadoc.dir" value = "doc"/>
<property name = "build.dir" value = "${web.dir}/WEB-INF/classes"/>
<property name = "name" value = "fax"/>
<path id = "master-classpath">
<fileset dir = "${web.dir}/WEB-INF/lib">
<include name = "*.jar"/>
</fileset>
<pathelement path = "${build.dir}"/>
</path>
<target name = "javadoc">
<javadoc packagenames = "faxapp.*" sourcepath = "${src.dir}"
destdir = "doc" version = "true" windowtitle = "Fax Application">
<doctitle><![CDATA[<h1> = Fax Application = </h1>]]></doctitle>
<bottom><![CDATA[Copyright 2011. All Rights Reserved.]]></bottom>
<group title = "util packages" packages = "faxapp.util.*"/>
<group title = "web packages" packages = "faxapp.web.*"/>
<group title = "data packages" packages = "faxapp.entity.*:faxapp.dao.*"/>
</javadoc>
</target>
<target name = "usage">
<echo message = ""/>
<echo message = "${name} build file"/>
<echo message = "-----------------------------------"/>
<echo message = ""/>
<echo message = "Available targets are:"/>
<echo message = ""/>
<echo message = "deploy --> Deploy application as directory"/>
<echo message = "deploywar --> Deploy application as a WAR file"/>
<echo message = ""/>
</target>
<target name = "build" description = "Compile main source tree java files">
<mkdir dir = "${build.dir}"/>
<javac destdir = "${build.dir}" source = "1.5" target = "1.5" debug = "true"
deprecation = "false" optimize = "false" failonerror = "true">
<src path = "${src.dir}"/>
<classpath refid = "master-classpath"/>
</javac>
</target>
<target name = "deploy" depends = "build" description = "Deploy application">
<copy todir = "${deploy.path}/${name}"
preservelastmodified = "true">
<fileset dir = "${web.dir}">
<include name = "**/*.*"/>
</fileset>
</copy>
</target>
<target name = "deploywar" depends = "build" description =
"Deploy application as a WAR file">
<war destfile = "${name}.war" webxml = "${web.dir}/WEB-INF/web.xml">
<fileset dir = "${web.dir}">
<include name = "**/*.*"/>
</fileset>
</war>
<copy todir = "${deploy.path}" preservelastmodified = "true">
<fileset dir = ".">
<include name = "*.war"/>
</fileset>
</copy>
</target>
<target name = "clean" description = "Clean output directories">
<delete>
<fileset dir = "${build.dir}">
<include name = "**/*.class"/>
</fileset>
</delete>
</target>
<!-- ============================================================ -->
<!-- Tomcat tasks -->
<!-- ============================================================ -->
<path id = "catalina-ant-classpath">
<!-- We need the Catalina jars for Tomcat -->
<!-- * for other app servers - check the docs -->
<fileset dir = "${appserver.lib}">
<include name = "catalina-ant.jar"/>
</fileset>
</path>
<taskdef name = "install" classname = "org.apache.catalina.ant.InstallTask">
<classpath refid = "catalina-ant-classpath"/>
</taskdef>
<taskdef name = "reload" classname = "org.apache.catalina.ant.ReloadTask">
<classpath refid = "catalina-ant-classpath"/>
</taskdef>
<taskdef name = "list" classname = "org.apache.catalina.ant.ListTask">
<classpath refid = "catalina-ant-classpath"/>
</taskdef>
<taskdef name = "start" classname = "org.apache.catalina.ant.StartTask">
<classpath refid = "catalina-ant-classpath"/>
</taskdef>
<taskdef name = "stop" classname = "org.apache.catalina.ant.StopTask">
<classpath refid = "catalina-ant-classpath"/>
</taskdef>
<target name = "reload" description = "Reload application in Tomcat">
<reload url = "${tomcat.manager.url}"username = "${tomcat.manager.username}"
password = "${tomcat.manager.password}" path = "/${name}"/>
</target>
</project>
In this example,, we have used Tomcat as our application server. First, in the build properties file, we have defined some additional properties.
The appserver.home points to the installation path to the Tomcat application server.
The appserver.lib points to the library files in the Tomcat installation folder.
The deploy.path variable now points to the webapp folder in Tomcat.
Applications in Tomcat can be stopped and started using the Tomcat manager application. The URL for the manager application, username and password are also specified in the build.properties file. Next, we declare a new CLASSPATH that contains the catalina-ant.jar. This jar file is required to execute Tomcat tasks through Apache Ant.
The catalina-ant.jar provides the following tasks
Sr.No.1-InstallTask
Installs a web application.
Class Name: org.apache.catalina.ant.InstallTask
Sr.No.2-ReloadTask
Reload a web application.
Class Name: org.apache.catalina.ant.ReloadTask
Sr.No.3-ListTask
Lists all web applications.
Class Name: org.apache.catalina.ant.ListTask
Sr.No.4-StartTask
Starts a web application.
Class Name: org.apache.catalina.ant.StartTask
Sr.No.5-StopTask
Stops a web application.
Class Name: org.apache.catalina.ant.StopTask
Sr.No.6-ReloadTask
Reloads a web application without stopping.
Class Name: org.apache.catalina.ant.ReloadTask
The reload task requires the following additional parameters
URL to the manager application
Username to restart the web application
Password to restart the web application
Name of the web application to be restarted
Let us issue the deploy-war command to copy the webapp to the Tomcat webapps folder and then let us reload the Fax Web application. The following outcome is the result of running the Ant file
C:\>ant deploy-war
Buildfile: C:\build.xml
BUILD SUCCESSFUL
Total time: 6.3 seconds
C:\>ant reload
Buildfile: C:\build.xml
BUILD SUCCESSFUL
Total time: 3.1 seconds
Once the above task is run, the web application is deployed and the web application is reloaded.
Ratings
Comments
Related Tutorials
- 01. Emulating Xbox 360 on PC for Running COD4 With Mods(3,500)
- 02. How to: Matrix Numbers | Batch File(1,908)
- 03. How to Password Protect Files on Windows(857)
- 04. How to play Socom 2/3/ and Combined Assault on PC(6,737)
- 05. Modern Warfare 2 Vac Ban Bypass Tutorial(6,147)
- 06. How to embed an image on TheTechGame(3,100)
- 07. [PC] NIOH 2 OTHER USER SAVE RESIGN(13,004)
- 08. Host bot lobbies! Full Tutorial!(11,294)
- 09. Unban yourself [Plutonium BO2](14,243)
- 10. Fall Guys - How to Change Your Name Color on Fall Guys(8,390)
- 11. Best Crosshair Settings for Valorant(6,529)
- 12. Othercide The Surgeon Boss Guide(2,544)
- 13. Othercide Remembrances Unlock Guide(4,470)
- 14. Othercide Beginners Tips and Tricks(2,712)
- 15. How to Fix Grounded Crashes, Loading Time, Low FPS and Other(4,848)
"Apache Ant Tutorial - Deploying Applications" :: Login/Create an Account :: 0 comments