问题
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>
回答1:
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
回答2:
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.
回答3:
Sometimes what I do is delete the folder or classes from tomcat/work/Catalina/...
来源:https://stackoverflow.com/questions/4765493/how-to-force-tomcat-to-reload-recently-compiled-class-war-files