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

心已入冬 提交于 2019-12-07 05:02:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!