Yishu Fang
Yishu Fang

Reputation: 9978

Why I have to restart Tomcat every time I change the code for my servlet?

When developing Servlet using Tomcat and Eclipse, I find that I have to restart Tomcat once I change the code for my Servlet, or I will see nothing that have been changed.

Why I have to do that?

and

Is there a way to see the change without restart Tomcat?

Upvotes: 5

Views: 3170

Answers (2)

Ernesto Campohermoso
Ernesto Campohermoso

Reputation: 7391

You can configure tomcat for reload automatically your servlets, configure the atribute reloadable to true of the Context.

For do Tomcat 7 you must do.

  1. Edit CATALINA_HOME/conf/context.xml
  2. Change:
<Context>

For:

<Context reloadable="true">

Where CATALINA_HOME is your tomcat installation

Upvotes: 4

Cameron
Cameron

Reputation: 1918

The java classes you're editing are compiled into class files, which are loaded by the Tomcat class loader when Tomcat starts up your app. But the class loader doesn't try to load new versions of the class after Tomcat starts up your application.

Eclipse does have a neat feature called "hot code replace" but it only works while you're debugging your application. In this case, Eclipse compiles your code as you're editing (whether or not your debugging), and then Eclipse attempts to load in the newly edited classes that it compiled. But it only works while debugging your app.

Another option is try a JVM plugin like JRebel that hot-swaps your classes regardless of whether or not your debugging.

Upvotes: 1

Related Questions