开发者

Having to restart tomcat whenever you make a change

Is there a way around having to restart tomcat every time a sma开发者_JAVA技巧ll change is made in java code?


Set reloadable attribute of <Context> element in context.xml to true.

<Context reloadable="true">

Then Tomcat will monitor changes in /WEB-INF/classes and /WEB-INF/lib and reload whenever appropriate.

If you're using an IDE, this is configureable as server setting as well. Here's how it look like in Eclipse:

Having to restart tomcat whenever you make a change


Check out Jrebel. It detects the code changes, compiles and deploys the war automatically, without having to restart the server. It saves a lot of time and improves the productivity.


If you need to modify classes without restarting consider Dynamic Code Evolution VM in addition to BalusC's answer to avoid permgen errors, for development.


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.


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.


You can also try DCEVM. I have written a howto about how to setup with tomcat + eclipse: Spring-mvc + Velocity + DCEVM


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.

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.


I've been using the Spring Loaded JVM 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.

If you use Eclipse with Tomcat integrated (WTP), you can see the steps I took here: https://stackoverflow.com/a/37064672/1034436

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜