Is there a way around having to restart tomcat every time a small change is made in java code?
8 Answers
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:

- 1,082,665
- 372
- 3,610
- 3,555
-
2
-
2@Val Go to the "Servers" view and double click on "Tomcat vx.x Server at xxx". – platypus May 12 '13 at 11:22
-
-
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.

- 5,704
- 8
- 43
- 48
-
15
-
Yes, but it does not cost much. i'm sure there must be some open source product for similar problem. Would be happy to know that, If any exists. – Vanchinathan Chandrasekaran Dec 06 '10 at 22:59
-
7Tomcat reboots so fast, you don't need Jrebel. You only really need Jrebel when using the very slow to reboot guys like websphere or JBOSS.. which are generally overkill but I digress. – bwawok Dec 07 '10 at 03:11
-
5Tomcat is fast, but some frameworks like Spring/Guice/Hibernate may have a slow initialization. Especially when they perform annotation scanning. – xmedeko Aug 01 '12 at 11:55
-
DCEVM + HotswapAgent tools together works much like JRebel, and they are free! – KrishPrabakar Mar 06 '20 at 06:41
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.

- 6,479
- 1
- 35
- 43
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.

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

- 3,452
- 1
- 26
- 23

- 1,823
- 21
- 28
-
The link is dows http://blog.rafaelsanches.com/2012/02/02/spring-mvc-velocity-dcevm/ – Yacino Aug 29 '21 at 18:08
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

- 1
- 1

- 595
- 1
- 6
- 21
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.

- 14,424
- 7
- 37
- 41
-
2
-
4And it isn't what OP is looking for. This only monitors for changes of `*.war` files in `webapps` and autodeploys whenever a new one is added or an existing one has changed. – BalusC Dec 06 '10 at 23:04
-
Why isn't it what the OP is looking for? Copying over the old war is a perfectly good way to redeploy an app. – Mike Baranczak Dec 06 '10 at 23:34
-
It works with raw classes as well. On my development machine I just point Tomcat at the class directory of Eclipse. I make a change, Eclipse automatically compiles, and a few seconds later Tomcat sees it and redeploys the context with the change. It's like the instant development of PHP or Python with a few seconds of delay. Then when we're ready, we WAR up the app, upload it to the server, put it in the right place, and Tomcat redeploys it, no restart needed. – MBCook Dec 07 '10 at 00:19