26

Is there a way around having to restart tomcat every time a small change is made in java code?

nuaavee
  • 1,336
  • 2
  • 16
  • 31

8 Answers8

36

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:

alt text

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
6

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.

4

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.

reevesy
  • 3,452
  • 1
  • 26
  • 23
Adisesha
  • 5,200
  • 1
  • 32
  • 43
3

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.

Anton Arhipov
  • 6,479
  • 1
  • 35
  • 43
2

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.

Mike Baranczak
  • 8,291
  • 8
  • 47
  • 71
1

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

reevesy
  • 3,452
  • 1
  • 26
  • 23
Rafael Sanches
  • 1,823
  • 21
  • 28
0

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

Community
  • 1
  • 1
martian111
  • 595
  • 1
  • 6
  • 21
0

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.

MBCook
  • 14,424
  • 7
  • 37
  • 41
  • 2
    Last I checked, autodeploy was on by default. – Mike Baranczak Dec 06 '10 at 22:59
  • 4
    And 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