5

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?

Yishu Fang
  • 9,448
  • 21
  • 65
  • 102
  • 1
    When you change a class you have to restart tomcat, when you change a JSP you don't have to. I know that there are options of "hot deploy" checkout JREBEL and such. – Nir Alfasi May 22 '13 at 02:56
  • 1
    possible duplicate of [Having to restart tomcat whenever you make a change](http://stackoverflow.com/questions/4371724/having-to-restart-tomcat-whenever-you-make-a-change) – Nir Alfasi May 22 '13 at 03:00
  • 2
    Hi this question has been asked before. Here's a link to help you with it. http://stackoverflow.com/a/4371821/2392140 – Jerry Loh May 22 '13 at 02:58
  • The second item in this question is a duplicate but the first one is unique. – Cameron Jul 25 '13 at 22:46

2 Answers2

4

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

Ernesto Campohermoso
  • 7,213
  • 1
  • 40
  • 51
1

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.

Cameron
  • 1,868
  • 3
  • 21
  • 38