At line 1 changed 1 line. |
I've been told I should use Tomcat's Ant Tasks (install, list, refresh, remove) in [AppFuse] to ease deployment of the app. So I tried that today (June 24, 2003). Here's how I set it up and what I found. I hope to use this page to get a consensus on how these tasks should be used. |
[I|MattRaible] finally figured out how to use Tomcat's Ant Tasks (install, remove, reload, start, stop, list) in [AppFuse] to ease deployment of the app. Below is a list of of the steps I used to integrate them into my build.xml file. |
At line 3 changed 1 line. |
1. First, I defined a tomcat.classpath for the catalina-ant.jar file. Putting in in $ANT_HOME/lib did not work - and this way seemed cleaner. So in properties.xml, I added: |
1. Rather than defining each task with a <taskdef>, I created a tomcatTasks.properties file with the following contents: |
At line 5 changed 3 lines. |
<path id="tomcat.classpath"> |
<fileset dir="${tomcat.home}/server/lib" includes="*.jar" /> |
</path> |
deploy=org.apache.catalina.ant.DeployTask |
install=org.apache.catalina.ant.InstallTask |
list=org.apache.catalina.ant.ListTask |
reload=org.apache.catalina.ant.ReloadTask |
remove=org.apache.catalina.ant.RemoveTask |
resources=org.apache.catalina.ant.ResourcesTask |
roles=org.apache.catalina.ant.RolesTask |
start=org.apache.catalina.ant.StartTask |
stop=org.apache.catalina.ant.StopTask |
undeploy=org.apache.catalina.ant.UndeployTask |
At line 16 added 80 lines. |
|
2. Then I created a tomcat.properties file with the following contents. Make sure the $CATALINA_HOME/conf/tomcat-users.xml file has an entry with username/password __admin/admin__ and that they have the __manager__ role. |
{{{ |
# Properties for Tomcat Server |
tomcat.server=localhost |
tomcat.manager.url=http://${tomcat.server}:8080/manager |
tomcat.username=admin |
tomcat.password=admin |
}}} |
|
3. I included a reference to tomcat.properties in my build.xml file: |
{{{ |
<property file="tomcat.properties"/> |
}}} |
|
4. Then I added all a single taskdef and all the targets/tasks I wanted to use to my build.xml file: |
{{{ |
<taskdef file="${ant-contrib.dir}/tomcatTasks.properties"> |
<classpath> |
<pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/> |
</classpath> |
</taskdef> |
<target name="install" description="Install application in Tomcat" |
depends="package-web"> |
<deploy url="${tomcat.manager.url}" |
username="${tomcat.username}" |
password="${tomcat.password}" |
path="/${webapp.name}" |
war="file:${webapp.dist}/${webapp.war}"/> |
</target> |
|
<target name="remove" description="Remove application in Tomcat"> |
<undeploy url="${tomcat.manager.url}" |
username="${tomcat.username}" |
password="${tomcat.password}" |
path="/${webapp.name}"/> |
</target> |
|
<target name="reload" description="Reload application in Tomcat"> |
<reload url="${tomcat.manager.url}" |
username="${tomcat.username}" |
password="${tomcat.password}" |
path="/${webapp.name}"/> |
</target> |
|
<target name="start" description="Start Tomcat application"> |
<start url="${tomcat.manager.url}" |
username="${tomcat.username}" |
password="${tomcat.password}" |
path="/${webapp.name}"/> |
</target> |
|
<target name="stop" description="Stop Tomcat application"> |
<stop url="${tomcat.manager.url}" |
username="${tomcat.username}" |
password="${tomcat.password}" |
path="/${webapp.name}"/> |
</target> |
|
<target name="list" description="List Tomcat applications"> |
<list url="${tomcat.manager.url}" |
username="${tomcat.username}" |
password="${tomcat.password}"/> |
</target> |
}}} |
|
__NOTE: There are a few things I discovered in this process:__ |
|
* If you put a ''context.xml'' file in your WAR's META-INF directory, the __deploy__ task will recognize it and use it. This is the same as defining your context in server.xml or putting an ''appname.xml'' file in $CATALINA_HOME/webapps. In Tomcat 4, this only works with the deploy task. In Tomcat 5, this will work with any war - even if you just drop it into $CATALINA_HOME/webapps. |
|
;:''That's a very slick feature IMO. Now if there was only a way to deploy the JDBC Driver with the WAR and have it auto-deployed to $CATALINA_HOME/common/lib.'' |
|
* All these tasks will overwrite your server.xml file in Tomcat 4.1.x. They do create a backup, but if you're having configuration issues after using these, revert back to your original server.xml. I've included a [minimal server.xml|server-minimal-4.1.29.xml] for Tomcat 4.1.29. Also, the war is deployed under the ''$CATALINA_HOME/work/Standalone/localhost/manager'' directory. |
* In Tomcat 4.1.x, the ''reload'' target doesn't work with WARs. You have to use "ant stop start" to simulate a reload. |
|
__The good news is that all of the issues that occur in Tomcat 4.1.x are gone in Tomcat 5.__ |
|
* In Tomcat 5, the server.xml is __not__ overwritten. The context.xml is extracted where you would expect it ($CATALINA_HOME/conf/Catalina/localhost), and the WAR is deployed (and expanded) to the webapps directory. |
|
* The ''reload'' target works in Tomcat 5 - providing you don't have any non-serializeable attributes in your session. |