Java : Boosting web application development - running Tomcat from Eclipse
This page last changed on Oct 02, 2007 by Kees de Kooter
Introduction
JSP development with Eclipse can be quite a drag, at least the way I did it. I used to build the war file with Maven (previously Ant) and deploy this file to my local tomcat instance (using the tomcat manager because I could not get the maven wagon plugin to work properly). Since eclipse only offers some basic xml validation at best my JSPs often contain a lot of errors at first. I took the habit of deploying wars exploded, so I could manually edit the deployed JSP files. Tomcat picks up changes instantly. Now I only had to copy-paste these changes back to my source files in eclipse .
Attempts to improve
I first tried the new Eclipse Callisto release with the web tool installed. You can create a "Dynamic Web Project" and configure an embedded tomcat server. This saves the manual deployment step. Unfortunately every change to a source file (both .jsp and .java) leads to a new deploy of the project on this embedded server.
Jetty Eclipse plugin
Unlike the eclipse web tools the Jetty Eclipse plugin (http://jettylauncher.sourceforge.net) uses the jsp files that are in the source tree and picks up changes immediately. This enables you to edit JSP files interactively.
Since my applications are usually deployed on Tomcat, I kept on the lookout for a Tomcat solution. And guess what. The solution was available, without using any fancy plugins, only the standard Callisto stuff
Running Tomcat 5.x from Eclipse
Create a Run configuration of type "Java Application"
Main class
org.apache.catalina.startup.Bootstrap
Program arguments
start -config %TOMCAT_HOME%/conf/server.xml
VM arguments
-Dcatalina.home=%TOMCAT_HOME% -Djava.endorsed.dirs=%TOMCAT_HOME%/common/endorsed -Dcatalina.base=%TOMCAT_HOME% -Djava.io.tmpdir=%TOMCAT_HOME%/temp
Classpath
%TOMCAT_HOME%/bin/bootstrap.jar JRE System Library Apache Tomcat vx.x // Server runtime configured under Preferences / Servers The project
Create a context.xml for the application in %TOMCAT_HOME%/conf/Catalina/localhost in which the
docBase
points to the directory containingWEB-INF
in the Eclipse project.<?xml version="1.0" encoding="ISO-8859-1"?> <Context displayName="metronome" docBase="/<path-to>/src/main/webapp" path="/<webapp-name>" reloadable="true"> <Logger className="org.apache.catalina.logger.SystemOutLogger" verbosity="4" timestamp="true"/> </Context>
Click "Run" or "Debug"
Eureka!
Now it is possible to debug java and jsp files and even better: hot swap modified code. A major improvement in development productivity!
Tomcat 6.0
" -config %TOMCAT_HOME%/conf/server.xml" does not work and is not necessary.