Helper class to simplify starting an embedded Tomcat in a development environment for a Maven webapplication project.
Add this dependency to your project.
<dependency>
<groupId>ch.rasc</groupId>
<artifactId>embeddedtc</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
and start the embedded Tomcat with ch.rasc.embeddedtc.EmbeddedTomcat.
This starts a Tomcat on port 8080 with a context path "/" and a context directory
that points to current_dir + /src/main/webapp
If you need more control create a class in your project (e.g. StartTomcat) and create an instance of EmbeddedTomcat, call the configure methods and start it with startAndWait()
public class StartTomcat {
public static void main(String[] args) throwsException {
EmbeddedTomcat etc = new EmbeddedTomcat(9999);
etc.setContextDirectory("/home/mywebapp");
etc.setTempDirectoryName("tmp");
etc.addContextEnvironmentString("key", "value");
etc.startAndWait();
}
}
or with method chaining
public class StartTomcat {
public static void main(String[] args) throwsException {
EmbeddedTomcat.create()
.setPort(9999)
.setContextDirector("/home/mywebapp")
.setTempDirectoryName("tmp")
.addContextEnvironmentString("key", "value")
.startAndWait();
}
}
CHANGELOG
1.0 July 11, 2012
- Moved to a new package ch.ralscha -> ch.rasc
- Updated to Tomcat 7.0.29
0.0.9 June 21, 2012
- Updated to Tomcat 7.0.28
0.0.8 May 21, 2012
- Updated ecj to 3.7.2
- Fix bug in installSlf4jBridge. install() does not have a parameter
0.0.7 April 17, 2012
- Removed addInitializer(..) method.
Directory WEB-INF/classes is now mapped to ./target/classes and therefore all the Servlet 3.0 Annotations and ServletContainerInitializer are now working out of the box.
0.0.6 March 9, 2012
- Updated to Tomcat 7.0.27
0.0.5 March 9, 2012
- Bugfix: Make class ContextConfig public. Digester cannot access class if it has package visibility
- All config methods now return the EmbeddedTomcat instance to enable method chaining
- Changed parameters to final
0.0.4 March 2, 2012
- Add a new method addContextEnvironmentAndResourceFromFile(File f) Reads ContextEnvironment and Contextresource from a file and adds it to the embedded Tomcat
- Changed the way resource jars are loaded. In older version the ZipFile was closed after starting Tomcat
and was no longer able to read content from the jar file.
- Moved default temporary directory to the projects target directory
- TomcatTest: Now deletes temp directory before starting Tomcat
0.0.3 February 26, 2012
- The start() method no longer blocks after starting Tomcat
- Added a new method startAndWait() that blocks the program after starting Tomcat
- Added setSilent(boolean) method. If set to true it disables output messages.
- Added new constructor EmbeddedTomcat(String contextPath).
Creates Tomcat with specified context path and port 8080
0.0.2 February 25, 2012
- Convert exceptions to RuntimeException
- Starts by default a shutdown listener on the shutdown port (port + 1000)
- Before starting a new Tomcat it tries to stop a previous one by sending a command to the shutdown port.
0.0.1 February 24, 2012
- Initial version