2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2020

10/31/2006: Embedded Tomcat 5.5.17 Eclipse Project

I like to use Tomcat because of its simplicity. I’m sure that there are many reasons to use the embedded version of Tomcat, I’m using it because I can start a vanilla Tomcat engine in under one second. Additionally, it’s easy to place all of the configuration files under version control when all of the files are part of a Eclipse project.

You can download a Zip file containing a working example of embedded Tomcat by clicking the title above. Make sure that you edit the .classpath file and change the location of the Jar files to whereever you have installed Tomcat.

If you want to follow the steps that I took instead of downloading the zip file, here they are:

  1. Create a Java class to start Tomcat:
package com.affy;
import org.apache.catalina.startup.Bootstrap;
public class EmbeddedTomcat {
 public static void main(String[] args) throws Exception {
  Bootstrap bootStrap = new Bootstrap();
  bootStrap.init();
  bootStrap.start();
 }
}
  1. Update your classpath so it contains the following jar files.
TOMCAT_HOME/bin/bootstrap.jar
TOMCAT_HOME/bin/commons-logging-api.jar
TOMCAT_HOME/common/lib/commons-el.jar
TOMCAT_HOME/common/lib/jasper-compiler.jar
TOMCAT_HOME/common/lib/jasper-compiler-jdt.jar
TOMCAT_HOME/common/lib/jasper-runtime.jar
TOMCAT_HOME/common/lib/jsp-api.jar
TOMCAT_HOME/common/lib/naming-factory.jar
TOMCAT_HOME/common/lib/naming-resources.jar
TOMCAT_HOME/common/lib/servlet-api.jar
TOMCAT_HOME/server/lib/catalina.jar
TOMCAT_HOME/server/lib/catalina-cluster.jar
TOMCAT_HOME/server/lib/catalina-storeconfig.jar
TOMCAT_HOME/server/lib/commons-modeler.jar
TOMCAT_HOME/server/lib/servlets-default.jar
TOMCAT_HOME/server/lib/tomcat-ajp.jar
TOMCAT_HOME/server/lib/tomcat-coyote.jar
TOMCAT_HOME/server/lib/tomcat-util.jar
TOMCAT_HOME/server/lib/tomcat-http.jar
  1. Create a conf directory with the following files (copied directly from the conf in TOMCAT_HOME.
catalina.policy
catalina.properties
context.xml
logging.properties
server.xml
tomcat-users.xml
web.xml
  1. Create the webapps and webapps/ROOT directories.

  2. Create a webapps/ROOT/index.html file with any content you’d like.

  3. Run the EmbeddedTomcat Java program. This step will automatically create a work directory.

  4. Connect to http://localhost:8080/ with your browser and you should see the index.html page that you created in step 5.

Good luck and Have Fun playing with your embedded Tomcat!

10/31/2006: Embedded Tomcat; Fixing the 'No Java Compiler available' error.

I am investigating the use of embedded Tomcat in one of my projects. During my testing, I ran into an error message:

No Java compiler available

I was unable to find significant information about this message via Google so I downloaded the Tomcat source and poked around. To make a short story shorter, include the following jar files to fix this issue:

TOMCAT_HOME\common\lib\jasper-compiler.jar
TOMCAT_HOME\common\lib\jasper-compiler-jdt.jar