nuaavee
nuaavee

Reputation: 1356

Having to restart tomcat whenever you make a change

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

Upvotes: 26

Views: 32676

Answers (8)

martian111
martian111

Reputation: 593

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

Upvotes: 0

Rafael Sanches
Rafael Sanches

Reputation: 1823

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

Upvotes: 1

Adisesha
Adisesha

Reputation: 5258

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.

Upvotes: 4

Anton Arhipov
Anton Arhipov

Reputation: 6591

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.

Upvotes: 3

BalusC
BalusC

Reputation: 1109532

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

Upvotes: 36

Mike Baranczak
Mike Baranczak

Reputation: 8374

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.

Upvotes: 2

MBCook
MBCook

Reputation: 14514

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.

Upvotes: 0

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.

Upvotes: 6

Related Questions