Java 每当您进行更改时都必须重新启动 tomcat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4371724/
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
Having to restart tomcat whenever you make a change
提问by nuaavee
Is there a way around having to restart tomcat every time a small change is made in java code?
有没有办法避免每次在 Java 代码中进行小的更改时都必须重新启动 tomcat?
采纳答案by BalusC
Set reloadable
attribute of <Context>
element in context.xml
to true
.
将元素的reloadable
属性设置为.<Context>
context.xml
true
<Context reloadable="true">
Then Tomcat will monitor changes in /WEB-INF/classes
and /WEB-INF/lib
and reload whenever appropriate.
然后 Tomcat 将监视/WEB-INF/classes
和 中的更改/WEB-INF/lib
并在适当时重新加载。
If you're using an IDE, this is configureable as server setting as well. Here's how it look like in Eclipse:
如果您使用的是 IDE,这也可以配置为服务器设置。下面是它在 Eclipse 中的样子:
回答by Vanchinathan Chandrasekaran
回答by MBCook
Yes. You can set tomcat to autodeploy and it will pick up the changes automatically. It still redeploys, but it's much faster. Just add "autodeploy="true"" to your Host entry in the server.xml config file.
是的。您可以将 tomcat 设置为 autodeploy,它会自动获取更改。它仍然会重新部署,但速度要快得多。只需将 "autodeploy="true"" 添加到 server.xml 配置文件中的主机条目。
That's what we do where I work. When it's time to update one of our applications we just drop the new WAR file on top of the old one and Tomcat unpacks and deploys it automatically.
这就是我们在我工作的地方所做的。当需要更新我们的应用程序之一时,我们只需将新的 WAR 文件放在旧的文件之上,Tomcat 就会自动解压缩并部署它。
回答by Mike Baranczak
You don't have to restart Tomcat, just re-deploy the application. There are different ways to do that (google "tomcat deploy" and you'll get a lot of pointers) but the simplest is to copy the newly created war file into Tomcat's webapps directory. Tomcat will automatically detect when the file is updated, and re-start the application.
您不必重新启动Tomcat,只需重新部署应用程序即可。有不同的方法可以做到这一点(谷歌“tomcat deploy”,你会得到很多指针),但最简单的方法是将新创建的 war 文件复制到 Tomcat 的 webapps 目录中。Tomcat 会自动检测文件何时更新,并重新启动应用程序。
回答by Adisesha
If you need to modify classes without restarting consider Dynamic Code Evolution VMin addition to BalusC's answer to avoid permgen errors, for development.
如果您需要在不重新启动的情况下修改类,除了 BalusC 的答案以避免 permgen 错误之外,还可以考虑Dynamic Code Evolution VM,以进行开发。
回答by Anton Arhipov
Even if Tomcat is generally very fast on the startup, it depends very much on your application, how quickly it can initialize itself. If there is a damn big Spring application context, with all kinds of integrations and Hibernate mappings, I'd be pretty sure that the boot will take 1,5 seconds to start Tomcat, but 1,5 minutes to start your application. JRebel could really help here.
即使 Tomcat 通常在启动时非常快,它在很大程度上取决于您的应用程序,它可以多快地初始化自己。如果有一个该死的大型 Spring 应用程序上下文,具有各种集成和 Hibernate 映射,我很确定启动需要 1.5 秒来启动 Tomcat,但需要 1.5 分钟来启动您的应用程序。JRebel 在这里真的可以提供帮助。
回答by Rafael Sanches
You can also try DCEVM. I have written a howto about how to setup with tomcat + eclipse: Spring-mvc + Velocity + DCEVM
您也可以尝试 DCEVM。我写了一篇关于如何使用 tomcat + eclipse 进行设置的方法:Spring-mvc + Velocity + DCEVM
回答by martian111
I've been using the Spring LoadedJVM agent to avoid restarting Tomcat or reloading the application (which can take a while for Spring web apps). I configure my Tomcat server in Eclipse along with "Automatically publish when resources change" to get changes to take effect nearly immediately.
我一直在使用Spring LoadedJVM 代理来避免重新启动 Tomcat 或重新加载应用程序(这对于 Spring Web 应用程序可能需要一段时间)。我在 Eclipse 中配置了我的 Tomcat 服务器以及“资源更改时自动发布”以使更改几乎立即生效。
If you use Eclipse with Tomcat integrated (WTP), you can see the steps I took here: https://stackoverflow.com/a/37064672/1034436
如果您使用 Eclipse 与 Tomcat 集成(WTP),您可以看到我在这里采取的步骤:https: //stackoverflow.com/a/37064672/1034436