Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Tomcat quick in loading changes to make Java web development fast

Tags:

java

tomcat

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:

  1. When I make a change to JSP, it should be auto loaded, instead of on-1st-request.

  2. 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.

like image 813
Asif Shahzad Avatar asked Jan 14 '11 03:01

Asif Shahzad


People also ask

What is reload in Tomcat?

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.

What is hot deployment in Tomcat?

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.


2 Answers

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.

like image 87
Yuval Rimar Avatar answered Nov 02 '22 23:11

Yuval Rimar


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! :)

like image 35
Chris Dennett Avatar answered Nov 03 '22 00:11

Chris Dennett