org.apache.tomcat.startup.EmbededTomcat
Use this class to embed tomcat in your application. If all you want is to start/stop tomcat, with minimal customization, you can use Main.main() This class is designed as a java bean, where you set different properties, then call methods to perform actions. The main method is "execute", that will start tomcat. Few other methods allow to perform different other tasks. EmbededTomcat is usable as an "ant" task as well, using the TaskAdapter. ( see sample - TODO XXX ). Adding tomcat to your application: - Create a java class that will act as adapter and start tomcat ( and hold your customization code ). The class and all the files in TOMCAT_HOME/lib/common must be available in the class loader. lib/container and lib/apps should _not_ be visible, EmbededTomcat will handle that. All the application files you want visible from tomcat must be included as well. ADVANCED1. Completely separated classloader - In your adapter, create an instance of EmbededTomcat. - set properties you want to customize. - add all interceptors including your application-specific. That includes the connector modules ( shortcuts are provided for common sets of modules and for common connector configuration ). - add the root context ( required ) and any other contexts you want. More context can be added at runtime. You can also use existing configuration modules that automatically add/deploy Contexts. - call start(). Tomcat will initialize and start. The method returns when everything is ready. - You can add/remove contexts at runtime. - call stop(). Tomcat will clean up all resources and shutdown ( clean shutdown ). All common modules have been tested and shouldn't leave any garbage, however it is possible that user code will leave threads or other garbage ( i.e. not clean on destroy ). If tomcat is run in a sandbox, this shouldn't be a problem ( as untrusted servlets can't create threads ). It is your responsiblity to make sure all apps you trust or custom modules support clean shutdown. - ADVANCED2. You can throw away the classloader, and use another one if you start again. That would take care of all garbage and classes except threads and associated objects ( there is no way to handle dangling threads except killing them, assuming you can distinguish them from your own threads ). All file paths _should_ be absolute. If not, you should set "home" and make sure you include the "PathSetter" module before anything else.
@author Costin Manolache