如何在不重新启动整个服务的情况下更新 Tomcat 网络应用程序?

我是 Tomcat的新手。我们有一个开发机器与大约5个应用程序运行。尽管它是 dev,但是我们的客户在测试期间使用它的频率非常高。

因此,假设我们需要对一个类文件做一个小小的更改。现在,我们必须关闭 Tomcat (影响其他四个应用程序) ,删除 WAR文件(和 web 应用程序目录) ,重新部署新的 WAR文件并重新启动 Tomcat

当然,这会让一些人感到不安,因为它会破坏所有应用程序的所有登录会话。

还有更好的办法吗?我的意思是,有没有一种方法可以只重新加载已经更改的 同学们,而不是开发计算机上的所有内容?

谢谢。

140569 次浏览

Have you tried to use Tomcat's Manager application? It allows you to undeploy / deploy war files with out shutting Tomcat down.

If you don't want to use the Manager application, you can also delete the war file from the webapps directory, Tomcat will undeploy the application after a short period of time. You can then copy a war file back into the directory, and Tomcat will deploy the war file.

If you are running Tomcat on Windows, you may need to configure your Context to not lock various files.

If you absolutely can't have any downtime, you may want to look at Tomcat 7's Parallel deployments You may deploy multiple versions of a web application with the same context path at the same time. The rules used to match requests to a context version are as follows:

  • If no session information is present in the request, use the latest version.
  • If session information is present in the request, check the session manager of each version for a matching session and if one is found, use that version.
  • If session information is present in the request but no matching session can be found, use the latest version.

In conf directory of apache tomcat you can find context.xml file. In that edit tag as <Context reloadable="true">. this should solve the issue and you need not restart the server

There are multiple easy ways.

  1. Just touch web.xml of any webapp.

    touch /usr/share/tomcat/webapps/<WEBAPP-NAME>/WEB-INF/web.xml
    

You can also update a particular jar file in WEB-INF/lib and then touch web.xml, rather than building whole war file and deploying it again.

  1. Delete webapps/YOUR_WEB_APP directory, Tomcat will start deploying war within 5 seconds (assuming your war file still exists in webapps folder).

  2. Generally overwriting war file with new version gets redeployed by tomcat automatically. If not, you can touch web.xml as explained above.

  3. Copy over an already exploded "directory" to your webapps folder