views:

35

answers:

1

I have two applications deployed on tomcat. For each application I have defined their own context in $CATALINA_HOME/conf/Catalina/localhost where JDBC datasource is defined. When I undeploy one of the application using ant script context of this application is deleted, so on the next start of the tomcat application cannot be deployed because it doesnt have JDBC connection defined. Is there any solution to this problem?

A: 

I think this is a Tomcat bug. I filed a bug report but the fix is complicated.

Tomcat can deploy application in 3 ways,

  1. Directory, like webapps/myapp.
  2. WAR, like webapps/myapp.war.
  3. Context fragment, which is what you are using.

If you use #3 but the app or war are in webapps, Tomcat will be confused with #1 or #2. When redeploying directory or war, it supposes to remove context fragment.

My workarounds are,

  1. If you use directory, put it somewhere other than APPBASE (webapps). If you use WAR, put it somewhere else also and don't explode it.
  2. We deploy our app using a script. In the script, the fragment is copied over every time after app is undeployed.

Here is a sample fragment for WAR deployment,

<Context docBase="/anywhere/but/webapps/myapp.war"
    swallowOutput="true" unpackWAR="false" />

Please notice not every app runs in unpacked mode. You can't read any resources as files from the WAR in unpacked mode.

ZZ Coder
Thanks for you reply. We have defined database connection as a resource so we will try to make it your way and write script that will copy context fragments after each undeploy and I hope it will help
Peter