java 如何强制 tomcat 重新加载最近编译的类/war 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4765493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 07:55:40  来源:igfitidea点击:

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

javatomcat6

提问by Manidip Sengupta

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.

我们有一组在 tomcat 引擎上运行的 servlet。当我们编译一个 java 文件并构建 war 时,tomcat 需要不确定的时间来重新加载它。有时 3 秒,有时 30 秒,等等。当前的解决方法是停止 tomcat 并使用 shell 脚本重新启动它。我们将 autodeploy 和 reloadable 标志设置为 true,但它不能可靠地工作。知道如何做到这一点吗?指针也很感激。这是关于 ubuntu 上的 tomcat v6.0.20。

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

这是我们的 conf/server.xml 文件的摘录:

<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>

回答by Stephen C

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

一种可能性是向Tomcat Manager App发送适当的请求;例如这样的事情:

http://localhost:8080/manager/text/reload?path=/examples

回答by schmmd

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!

如果您在开发过程中遇到此问题,我强烈推荐jetty。它可以嵌入到您的代码中,因此您可以在您的代码中运行一个类并为您的 web 应用程序启动服务器!

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).

如果你使用它作为你的构建环境,你可以在 Eclipse 中调试应用程序(我记得在 Eclipse 中调试 Tomcat 应用程序,但我忘记了如何),制作一个 ant 构建目标来运行 jetty(即 ant jetty),或者使用 maven 启动您的码头服务器使用码头插件 (mvn jetty:run)。

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

使用 jetty,您还可以托管类似于 Tomcat 的服务器,您可以在其中复制新的War并立即生效。

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

我们将 Tomcat 用于我们的服务器应用程序,因为对它的支持很熟悉,但我发现 jetty 对开发至关重要。

回答by Christian Vielma

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

有时我所做的是从 tomcat/work/Catalina/... 中删除文件夹或类