Integrating tomcat and eclipse as a hot-deploy environment

Viewed 98857

I would like to setup eclipse and tomcat in an integrated fashion such that changes to my JSPs and servlets(if possible) are reflected immedietely without requiring a deployment.

Ok, this is one of those questions that has plenty of answers all across the internet but they all seem different. (use Sysdeo plugin, use JBOss plugin, do stuff with an outdated Eclipse, use MyEclipse instead etc.) and I couldn't find 1 definitive resource to refer to. So for my benefit, what is the simplest and most recommended procedure to set this up ?

This assumes I have eclipse and tomcat running independently. I actually have managed to integrate them in a non-hot deploy fashion using instructions here : http://www.ibm.com/developerworks/opensource/library/os-eclipse-tomcat/index.html

Eclipse version Version: 3.4.2 (Ganymede) Tomcat v6.0.20

16 Answers

Simply let eclipse write the class files directly to the $TOMCAT/webapps/MyWebApp/WEB_INF/classes directory. Then, configure apache-tomcat to check if the class files have been updated, and reload them if they have.

To configure tomcat to auto-reload a class when it changes, you need to

edit $TOMCAT/conf/context.xml and set :

<Context reloadable="true"> 

You may also have to edit and reload your webapps/$YourWebApp/web.xml file and include :

<web-app reloadable="true">

I can't remember if both changes are needed but that's how I configured my tomcat-6.0.18 to auto-reload.

Disclaimer: I'm just a happy customer, I don't work for Zero Turnaround and I'm not in any way affiliated with them.

Check out JRebel - it allows you to code without web application restarts. It basically works by instrumenting your classes and adapting their changes. It handles many more cases than hot deploy, including:

  • Adding/removing methods
  • Adding/removing constructors
  • Changing interfaces
  • Adding/removing implemented interfaces

It's commercial, ( pricing details, $550/year as of June 2018 ) , and it has a lots of plugins for third party frameworks, including:

  • Guice
  • Spring
  • Struts 2

You get a free trial quite painlessly - I suggest you give it a shot.

Change your workspace in Eclipse to \tomcat\webapps Since it is just for your work, this should work fine. Whatever changes you make in Eclipse is in the same directory tomcat looks for applications to deploy

Why not use an integrated tomcat server from with in eclipse if this is just for development? You can configure servers under window->preferences. Once it's configured if you have a jsp called page.jsp you can right click it and select run on server. Under preferences->general->Web browser you can chose weather to use the built in browser or an external one. Make some changes to your jsp, save, and refresh your page from the browser. The changes will be automatically reflected once you save and refresh your browser.

In your development environment, just point your Tomcat server to look for JSPs in whatever directory you're developing them in. As soon as you save the file, you'll be able to see the changes then.

Are you open to using Jetty for development purposes?

If so, it's pretty simple to use with Maven - just run mvn jetty:run

This may not be the best way, but it works for me.

  • $tomcat/conf/Catalina/localhost/.xml
  • $contextPath/webapp/web/WEB-INF/lib/*.jar
  • $contextPath/webapp/web/
  • $eclispeWorkbench/project-servlet/src/
  • $eclispeWorkbench/project-servlet/servlet.jardesc (should export jar to lib dir in $contextPath)
  • $eclipseWorkbench/project-jsp/

I use an rsync command to sync up changes from my jsp project to the $contextPath.

Use remote debugging in Eclipse for Tomcat which will allow limited hot-swapping of code. If you change static fields or add methods, you will need to export the jar and restart the context.

In Eclipse, click on the Project in the top menu and make sure “Build Automatically” is selected. This fixed my problem. I was running Eclipse with Tomcat using my workspace metadata. I was also running Maven in a Dynamic Web Module project. To verify, add your application to Tomcat. Start Tomcat from within Eclipse. Make sure your application is deployed and running. Open the Console tab in Eclipse. Make a change in your application. After a couple of seconds you should see your change getting automatically built and deployed to Tomcat.

Simplest, quickest: set Eclipse up to generate a WAR file when you build; as a post-build step, copy that WAR file into your tomcat webapps directory. Tomcat will recognize the change and refresh the site with no deployment necessary. Note that this isn't perfect; users using that webapp may have a less than optimal experience, as Tomcat restarts the webapp "under" them; but this does fit your request.

Related