Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force tomcat to reload recently compiled class/war files

Tags:

java

tomcat6

We have a set of running servlets on a tomcat engine. When we compile a java file and build the war, tomcat takes an indeterminate amount of time to reload it. Sometimes 3 seconds, sometimes 30, etc. Current workaround is to stop tomcat and restart it using a shell script. We set up the autodeploy and reloadable flag to true but it is not working reliably. Any idea how to make this happen? Pointers appreciated, too. This is about tomcat v6.0.20 on ubuntu.

Here is an extract of our conf/server.xml file:

<Engine name="Catalina" defaultHost="localhost">

  <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
         resourceName="UserDatabase"/>

  <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">

    <DefaultContext reloadable="true">
    </DefaultContext>

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

  </Host>
</Engine>
like image 802
Manidip Sengupta Avatar asked Jan 22 '11 01:01

Manidip Sengupta


3 Answers

One possibility is to send an appropriate request to the Tomcat Manager App; e.g. something like this:

http://localhost:8080/manager/text/reload?path=/examples
like image 138
Stephen C Avatar answered Oct 17 '22 02:10

Stephen C


If you are having this problem for development, I highly recommend jetty. It is embeddable in your code so you can run a class in your code and start up a server for your webapp!

You can debug application in Eclipse if you use that as your build environment (I remember debugging Tomcat applications in Eclipse, but I've forgotten how), make an ant build target to run jetty (i.e. ant jetty), or use maven to start your jetty server using the jetty plugin (mvn jetty:run).

With jetty, you can also host a server similar to Tomcat, where you copy new wars and they take affect immediately.

We use Tomcat for our server applications because support is familiar with it, but I find jetty essential for development.

like image 39
schmmd Avatar answered Oct 17 '22 04:10

schmmd


Sometimes what I do is delete the folder or classes from tomcat/work/Catalina/...

like image 1
Christian Vielma Avatar answered Oct 17 '22 04:10

Christian Vielma