Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 404
Yishu Fang Avatar asked May 22 '13 02:05

Yishu Fang


2 Answers

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

like image 198
Ernesto Campohermoso Avatar answered Sep 25 '22 16:09

Ernesto Campohermoso


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.

like image 27
Cameron Avatar answered Sep 22 '22 16:09

Cameron