Here are some ant macros that automatically create a context file for
in-place deployment without the nasty side effects when the app is
undeployed.
<import file="tomcat-manager-ant-macros.xml"/>
<tomcatDeployInPlace contextPath="/somecontext" docBase="/path/to/
exploded/webapp"/>
<project name="tomcat-manager">
<!-- This file defines macros for deploying and undeploying webapps via the tomcat manager. -->
<property environment="tomcat.manager.env"/>
<!-- define <trycatch> -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<!-- define tomcat tasks -->
<path id="tomcat.manager.classpath">
<pathelement location="${tomcat.manager.env.CATALINA_HOME}/server/lib/catalina-ant.jar"/>
</path>
<taskdef name="_tomcat.reload" classname="org.apache.catalina.ant.ReloadTask" classpathref="tomcat.manager.classpath"/>
<taskdef name="_tomcat.remove" classname="org.apache.catalina.ant.RemoveTask" classpathref="tomcat.manager.classpath"/>
<taskdef name="_tomcat.install" classname="org.apache.catalina.ant.InstallTask" classpathref="tomcat.manager.classpath"/>
<macrodef name="_checkTomcatPreconditions">
<sequential>
<fail unless="tomcat.manager.env.CATALINA_HOME" message="CATALINA_HOME environment variable must be set"/>
</sequential>
</macrodef>
<macrodef name="tomcatDeployInPlace">
<attribute name="docBase"/>
<attribute name="contextPath"/>
<attribute name="host" default="localhost"/>
<attribute name="port" default="8080"/>
<attribute name="username" default="admin"/>
<attribute name="password" default="laszlo"/>
<attribute name="tomcatManagerUrl" default="http://@{host}:@{port}/manager"/>
<sequential>
<_checkTomcatPreconditions/>
<echo>Deploying webapp context "@{contextPath}" from docBase "@{docBase}"</echo>
<echo>Tomcat manager url: @{tomcatManagerUrl}</echo>
<!-- Deploy using a context descriptor to prevent Tomcat 5.5 from copying
the whole webapp directory to $CATALINA_HOME/webapps.
The redundant path attribute is included for backwards compatibility with 5.0.x -->
<property name="temp.context.file" location="_temporary-context-descriptor.xml"/>
<echo file="${temp.context.file}"><![CDATA[
<Context path="@{contextPath}" docBase="@{docBase}" allowLinking="true"/>
]]></echo>
<_tomcat.install url="@{tomcatManagerUrl}" username="@{username}" password="@{password}"
path="@{contextPath}" config="file://${temp.context.file}"/>
<delete file="${temp.context.file}"/>
</sequential>
</macrodef>
<macrodef name="tomcatUndeploy">
<attribute name="contextPath"/>
<attribute name="host" default="localhost"/>
<attribute name="port" default="8080"/>
<attribute name="username" default="admin"/>
<attribute name="password" default="laszlo"/>
<attribute name="tomcatManagerUrl" default="http://@{host}:@{port}/manager"/>
<sequential>
<_checkTomcatPreconditions/>
<echo>Undeploying webapp context "@{contextPath}"</echo>
<echo>Tomcat manager url: @{tomcatManagerUrl}</echo>
<trycatch>
<try>
<_tomcat.remove url="@{tomcatManagerUrl}" username="@{username}"
password="@{password}" path="@{contextPath}"/>
</try>
<!-- Allow graceful failure if the webapp isn't deployed -->
<catch/>
</trycatch>
</sequential>
</macrodef>
</project>
On Jun 10, 2010, at 2:45 PM, Raju Bitter wrote:
In the 5.0 docs I found regarding the undeploy command:
"WARNING - This command will delete the contents of the web
application directory and/or ".war" file if it exists within the
appBase directory (typically "webapps") for this virtual host . The
web application temporary work directory is also deleted. If you
simply want to take an application out of service, you should use the
/stop command instead."
That would make sense. If you deploy an app through the local file
system using a directory outside the appBase dir (normally
$TOMCAT_HOME/webapps), an undeploy command will delete the webapp
folder and the temp folder.
Then I did some testing with Tomcat 6. If I use a context.xml file -
which I place in the $LPS_HOME folder - I can use the Tomcat manager
application to deploy and undeploy apps as we could with Tomcat 5.0.
Here's the context.xml I'm using:
<Context path="/trunk"
docBase="/Users/rajubitter/src/svn/openlaszlo/trunk-work/"
debug="0">
</Context>
I have that in my OL trunk folder:
/Users/rajubitter/src/svn/openlaszlo/trunk-work
In the Tomcat manager, I deploy a new webapp, using "/trunk" for the
field "Context Path (required):".
For the field "XML Configuration file URL:" I use
"/Users/rajubitter/src/svn/openlaszlo/trunk-work/context.xml"
When I undeploy the app, the directory is not deleted. Unfortunately,
using the ANT script with an additional attribute
config="${LPS_HOME}/context.xml"
the directory content is still copied into the webapps folder. Here's
the full XML for the ANT task I tested:
<deploy url="${tom.url}"
username="${tom.username}"
password="${tom.password}"
path="/${build.branch}"
localWar="${LPS_HOME}"
config="${LPS_HOME}/context.xml"
/>
But at least you could quickly redeploy the webapp by using the URL
http://localhost:8080/manager/html/reload?path=/trunk, if you have
authenticated with Tomcat manager app.
On Thu, Jun 10, 2010 at 11:10 PM, Raju Bitter
<[email protected]> wrote:
You could try to use web app stop and start tasks instead of
redeploy.
<target name="start"
description="start application on servlet container">
<echo message="app path: ${app.path}"/>
<start
url="${catalina.manager.url}"
username="${catalina.manager.username}"
password="${catalina.manager.password}"
path="${app.path}"/>
</target>
<target name="stop"
description="Stop application on servlet container">
<echo message="app path: ${app.path}"/>
<stop
url="${catalina.manager.url}"
username="${catalina.manager.username}"
password="${catalina.manager.password}"
path="${app.path}"/>
</target>
On Thu, Jun 10, 2010 at 11:00 PM, Raju Bitter <[email protected]
> wrote:
It should be in /tomcat/conf/Catalina/localhost
In my case, I have a version of trunk deployed using the path /
trunk-work, and here's the corresponding XML file's content:
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="/Users/rajubitter/src/svn/openlaszlo/trunk-work"
path="/trunk-work">
</Context>
The name of the generated file will be the same as the path you
have chosen for the app.
On Thu, Jun 10, 2010 at 10:55 PM, P T Withington <[email protected]>
wrote:
It looks like they must be. That's probably what's taking all
the tiem.
Where is this context descriptor file of which you speak?
I am a tomcat dummy.
On 2010-06-10, at 16:43, Raju Bitter wrote:
Tucker, when you deploy the app, is the content being copied
into Tomcat
webapps folder? What is the content of the context descriptor file
generated?
On Thu, Jun 10, 2010 at 10:32 PM, Raju Bitter <
[email protected]> wrote:
I had some problems when I used Java 6 with the error message
javax not
found, or something similar. That's the only thing I can
remember, Henry.
Could it be an error with the docbase setting for the context?
On Thu, Jun 10, 2010 at 9:46 PM, Henry Minsky <[email protected]
>wrote:
Wasn't Raju complaining at one point about a newer version
of tomcat
copying all the files from the working dir into it's own dir
instead ofjust
running from the directory? Raju?
On Thu, Jun 10, 2010 at 3:40 PM, P T Withington
<[email protected]> wrote:
And now webapp.deploy seems to take forever (1:43) and if
emacs has left
any .# temp files in WEB-INF tomcat silently declines to
deploy my servlet
(I guess) and serves up all my .lzx files as straight text.
Looking for suggestions...
--
Henry Minsky
Software Architect
[email protected]