Being able to hot deploy changes you make to your Java web applications is very important. This makes development more productive since it eliminates the build and deploy steps. You use your IDE to make changes and you can see and test your changes right away. Here are ways to do it when using Eclipse.
1. Servers View
The easiest way to hot deploy your Java web application is to create a Server in the Eclipse Servers view and run your web application inside the Server. For this article, We will use Tomcat 7 as our Server.
Your web application must be assigned the Dynamic Web Module Project Facet for this to work. If you didn’t create this web application using the Eclipse New Project Wizard, you will have to assign this Project Facet in Project Properties.
Now make changes to your controller and you should see Eclipse automatically reload the web application a few seconds after you save your changes.
2. Maven Jetty Plugin
If you use Maven to run your server, you can use the Jetty Plugin. It can be configured to periodically scan for changes and automatically redeploy the webapp.
Add the Jetty plugin in pom.xml and run jetty:run. Version 6.1.26 is the latest as of this writing.
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.26</version> <configuration> <scanIntervalSeconds>5</scanIntervalSeconds> </configuration> </plugin>
project-dir> mvn jetty:run
Now make changes to your controller in Eclipse and you should see the Maven Jetty plugin automatically reload the web application.
If you have to run Tomcat from the command line or as a service, you can use JRebel. If you need to reload libraries or you have a more complicated application setup, you also will have to use JRebel. There’s a small annual license fee, and it’s free for OSS developers.
To set up, get a JRebel license and install the JRebel Eclipse Plugin from the Eclipse update site http://www.zeroturnaround.com/update-site/. When prompted for a license, copy the license file to the plugin directory and point the license prompt to that file. The plugin directory is something like <eclipse-home>pluginsorg.zeroturnaround.eclipse.embedder_4.*jrebel, and this is where jrebel.jar lives. If you use Pulse, this will be under the Genuitec/Common folder.
To setup the web application, right click on the project and go to JRebel -> Generate rebel.xml in src/main/resources.
To setup Tomcat, create <tomcat-home>/bin/startup-jrebel. cmd and use this to run Tomcat.
@echo off set JAVA_OPTS=-javaagent:"<jrebel-home>jrebel.jar" %JAVA_OPTS% call "%~dp0startup.bat" %*
Now make changes to your controller in Eclipse and you should see JRebel automatically reload the class.
4. Exploded WAR
Another approach is to deploy an exploded war file, and configure Eclipse to write classes to it. You can write a custom Project Builder to copy the .class files to the exploded war file.
If your operating system supports it, you can also create a symbolic link so you don’t have to worry about copying the files. If you don’t want to deploy an exploded war file, just overwrite the .war file every time you make changes in Eclipse using a custom Builder and Tomcat should reload the web application automatically.
This Post Has One Comment
The Server View option nor the Exploded War version are not working..
I am trying to do Hotdeployment. Any changes that I do to the html or the services code is not shown on the server. I am annoyed to do everytime undeploy build and deploy the code for every small changes…
I am building a JSF webapplication in Eclipse4.0 and Tomcat7.0. I have built my application with Maven.
I am not sure how to do the Exploded war deployment as the war file and the exploded war content is in /target/myapp/.. folder.