views:

6220

answers:

8

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

A: 

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.

McWafflestix
ok...I guess I didnt make my intentions clear. I really am not interested in deploying the app to some users, but I'm trying to run a tomcat with eclipse for my everyday development needs and to shorten the feedback cycle of (make change) -> (See Result) instead of (Make Change) -> Deploy -> (See Result)
udit
+2  A: 

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 JavaRebel - 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, but not too expensive ( USD 59 Personal, USD 149 Corporate) , 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. It's even free for OSS development.

Robert Munteanu
+2  A: 

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.

Cameron
A: 

Are you open to using Jetty for development purposes?

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

matt b
+4  A: 

What I do, is simply to let eclipse write the class files directly to the $TOMCAT/webapps/MyWebApp/WEB_INF/classes directory, and then configure apache-tomcat to check if the classfile have been updated and reload it if it have.

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

edit $TOMCAT/conf/context.xml and set
    <Context reloadable="true">

--

    You may also have edit 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

Martin Tilsted
A: 

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.

TJ
+1  A: 

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

Sandeep Rajeev
+1  A: 

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.

Jared