My app uses Struts2 MVC, Spring JDBC Template with Eclipse IDE and Tomcat. Whenever I change a class code, I have to restart the Tomcat, which waste about 15-20 seconds every time.
I have configured hot-deployment i.e. on-java-class-change, context reloaded automatically, but it often fails, and I have to restart the Tomcat.
What I wish is:
When I make a change to JSP, it should be auto loaded, instead of on-1st-request.
When a java class is changed and build, only that class should be loaded, without restarting Tomcat, even whole context should not restart or reload.
If someone have used Jetty, please share - does Jetty provide better solution to these issues.
In PHP, you make a change in script, and access that page, its ready. I just wish it in Java.
On an Apache Tomcat server, to "reload" an application means to call a method of the StandardContext class called StandardContext. reload() on a given Context. This method creates a new classloader and new servlets, drops all references to the old servlets, and then calls the Servlet.
To remedy this situation, Tomcat provides a number of "hot deployment" options, which simply means that any deployments, redeployments, and adjustments to applications are made while the server is still running, rather than requiring it to stop. There are a number of ways to use hot deployment with Tomcat.
We are using embedded Jetty at work and it's a blast. See http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty for a guide on embedding Jetty.
The startup time on the Jetty side is extremely fast (1-2 seconds). In our case though spring takes a lot of time to initialize still.
It is easy to configure Jetty to reload jsps automatically just point it to a directory and not war file and jsps will reload automatically, something like this:
public class OneWebAppUnassembled
{
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
WebAppContext context = new WebAppContext();
context.setDescriptor(webapp+"/WEB-INF/web.xml");
context.setResourceBase("../test-jetty-webapp/src/main/webapp");
context.setContextPath("/");
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();
server.join();
}
}
Class reloading is possible using hot swap, I don't know if there are ready solutions for when hot swap doesn't work.
Have a look at JRebel. You have to pay for it, but it may be worth it in the long run for the time saved! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With