Blog Post


Eclipse: Hot Deploy to Tomcat

Sometimes there is a need to apply java code changes without complete application rebuild and Tomcat restart. The main idea here is just to copy compiled java classes to the application directory under Tomcat. Even if there is a jar with the same classes already deployed, it is not a problem, because application jars treated lower by Tomcat than class-files under the application classpath. Classes loading order, taken from tomcat howto:

  • Bootstrap classes of your JVM
  • System class loader classes (described above)
  • /WEB-INF/classes of your web application
  • /WEB-INF/lib/*.jar of your web application
  • $CATALINA_HOME/common/classes
  • $CATALINA_HOME/common/endorsed/*.jar
  • $CATALINA_HOME/common/i18n/*.jar
  • $CATALINA_HOME/common/lib/*.jar
  • $CATALINA_BASE/shared/classes
  • $CATALINA_BASE/shared/lib/*.jar


As an example we'll let’s create app-center-ui project in Eclipse. Here are the steps how to hot deploy changes to Tomcat:

1. First of all we need to disable scrub of target directory (we don't want to loose all files located in classpath directory, when a user clears project or clicks 'save'). Open project properties for app-center-ui (alt + Enter) -> Java Compiler -> Building. Enable project specific setting, disable 'scrub' option, click Apply, Ok:

liferay alfresco tomcat eclipse


2. Specify target directory. Target directory should be always a classes dir under your application in Tomcat.

a) Disable multiple target paths. Open project properties for app-center-ui (alt + Enter) -> Java Build Path -> Source -> Disable "Enable output folders for source folders". This option is disabled because we want to deploy all source dirs to one default target dir, otherwise you'll need to define target dir for every source dir (for src/main/java dir, for src/tests/java dir, ...).

b) Define default output folder. Click Browse:

liferay alfresco tomcat eclipse


Navigate to root (app-center-ui), click "Create new folder":

liferay alfresco tomcat eclipse


Type any folder name, click "Advanced >>", check "Link to folder in the file system", click "Browse":

liferay alfresco tomcat eclipse


Point a path to your %TOMCAT_DIR%/webapps/%APP%/WEB-INF/classes. Create this path if classes does not exist. Click Ok for every window (eclipse will ask to rebuild, to delete old classes).

3. Test results. After application rebuild, restart Tomcat.

Now on every user 'save'-click (if Build Automatically option enabled), you'll see deployed result without tomcat restart.

Comments (0)

Tags: eclipse


Leave a Comment