Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating tomcat and eclipse as a hot-deploy environment

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

like image 812
udit Avatar asked Jun 15 '09 22:06

udit


People also ask

Does Tomcat support hot deployment?

However, Tomcat also supports a variety of hot deployment options, allowing users to roll out new applications, or even update existing ones, while the server is still running.

How do I enable hot deployment in 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.

What is hot deployment in Tomcat?

If you need to deploy and undeploy your webapp without needing to restart the Tomcat JVM in order for the deployment and undeployment to take effect, you want "Hot Deployment." In this section, we focus on local filesystem hot deployment, where everything happens on one machine, as opposed to remote hot deployment, ...


2 Answers

There are two options.

First, Eclipse lets you do this, with a slight change of configuration (see also this detailed post)

  • add Tomcat to the server list
  • make the project "Dynamic web project" (Either through the creation wizard or through the facets section in the settings)
  • add the project to tomcat, and configure its "Deployment assembly"
  • double click tomcat from the list to open the configurations
  • Change "Publishing" to "Never publish automatically" (this means the server won't get restarted when you hit ctrl+s)
  • start tomcat in debug mode

This will still reflect code changes but won't restart the server.

Second, I've used the FileSync plugin for a long time:

  • configure the plugin to send all classes from the bin director to WEB-INF/classes of your tomcat installation (this is almost the same as configuring the deployment assembly)
  • configure all other resources to go to their respective locations
  • optionally, externalize all absolute paths from the filesync location settings to a single variable, and configure that variable in eclipse (thus you will be able to commit the filesync settings as well, if all members are using eclipse)
  • add Tomcat to the Servers list in eclipse, configure the "Server locations" option to be "Use tomcat installation" (the screen opens when you double-click tomcat from the servers list)
  • start tomcat in debug mode

It works perfectly for me that way. Every non-structural change is reflected immediately, without redeploy.

Update:
You can read more about the methods for hot-deploying here.
I also created a project that easily syncs the workspace with the servlet container.

like image 146
Bozho Avatar answered Sep 24 '22 15:09

Bozho


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.

like image 25
Martin Tilsted Avatar answered Sep 24 '22 15:09

Martin Tilsted