Tomcat supports multiple styles of configuration and startup - the most common and stable is server.xml-based, implemented in org.apache.catalina.startup.Bootstrap.
This class is for use in apps that embed tomcat.
Requirements:
There are a variety of 'add' methods to configure servlets and webapps. These methods, by default, create a simple in-memory security realm and apply it. If you need more complex security processing, you can define a subclass of this class.
This class provides a set of convenience methods for configuring web application contexts; all overloads of the
method addWebapp(). These methods are equivalent to adding a web application to the Host's appBase
(normally the webapps directory). These methods create a Context, configure it with the equivalent of the defaults
provided by conf/web.xml (see initWebappDefaults(String) for details) and add the Context to a
Host. These methods do not use a global default web.xml; rather, they add a LifecycleListener to configure
the defaults. Any WEB-INF/web.xml and META-INF/context.xml packaged with the application will be processed normally.
Normal web fragment and jakarta. processing will be applied.
In complex cases, you may prefer to use the ordinary Tomcat API to create webapp contexts; for example, you might
need to install a custom Loader before the call to Host#addChild(Container). To replicate the basic behavior
of the addWebapp methods, you may want to call two methods of this class: noDefaultWebXmlPath()
and getDefaultWebXmlListener().
getDefaultWebXmlListener() returns a LifecycleListener that adds the standard DefaultServlet, JSP
processing, and welcome files. If you add this listener, you must prevent Tomcat from applying any standard global
web.xml with ...
noDefaultWebXmlPath() returns a dummy pathname to configure to prevent ContextConfig from trying to
apply a global web.xml file.
This class provides a main() and few simple CLI arguments, see setters for doc. It can be used for simple tests and demo.
| Modifier and Type | Class and Description |
|---|---|
| public static class | Tomcat.
Fix reload - required if reloading and using programmatic configuration. |
| public static class | Tomcat.
Helper class for wrapping existing servlets. |
| public static class | Tomcat.
Fix startup sequence - required if you don't use web.xml. |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| protected String | |
| protected String | |
| private final Map | |
| protected int | |
| protected Server | |
| pack-priv static final String[] | |
| private boolean | |
| private static final StringManager | |
| private final Map | |
| private final Map | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Context | Returns: the deployed contextThe context mapping to use, "" for root context. contextPath, String Base directory for the context, for static files. Must exist, relative to the server home docBase)Add a context - programmatic mode, no default web.xml used. |
| public Context | Returns: the deployed contextThe host in which the context will be deployed host, String The context mapping to use, "" for root context. contextPath, String Base directory for the context, for static files. Must exist, relative to the server home dir)
|
| public Context | Returns: the deployed contextThe host in which the context will be deployed host, String The context mapping to use, "" for root context. contextPath, String The context name contextName, String Base directory for the context, for static files. Must exist, relative to the server home dir)
|
| public static void | addDefaultMimeTypeMappings(Context
The web application to which the default MIME type mappings should be added. context)Add the default MIME type mappings to the provide Context. |
| public void | |
| public Wrapper | Returns: The wrapper for the servletContext to add Servlet to contextPath, String Servlet name (used in mappings) servletName, String The class to be used for the Servlet servletClass)Equivalent to <servlet><servlet-name><servlet-class>. |
| public static Wrapper | Returns: The wrapper for the servletContext to add Servlet to ctx, String Servlet name (used in mappings) servletName, String The class to be used for the Servlet servletClass)Static version of |
| public Wrapper | Returns: The wrapper for the servletContext to add Servlet to contextPath, String Servlet name (used in mappings) servletName, Servlet The Servlet to add servlet)Add an existing Servlet to the context with no class.forName or initialisation. |
| public static Wrapper | Returns: The wrapper for the servletContext to add Servlet to ctx, String Servlet name (used in mappings) servletName, Servlet The Servlet to add servlet)Static version of |
| public void | |
| public Context | Returns: the deployed contextThe context mapping to use, "" for root context. contextPath, String Base directory for the context, for static files. Must exist and be an absolute path. docBase)This is equivalent to adding a web application to a Host's appBase (usually Tomcat's webapps directory). |
| public Context | Returns: The deployed ContextThe context mapping to use, "" for root context. contextPath, URL The location from which the WAR should be copied source)Copy the specified WAR file to the Host's appBase and then call |
| public Context | Returns: the deployed contextThe host in which the context will be deployed host, String The context mapping to use, "" for root context. contextPath, String Base directory for the context, for static files. Must exist and be an absolute path. docBase)This is equivalent to adding a web application to a Host's appBase (usually Tomcat's webapps directory). |
| public Context | Returns: the deployed contextThe host in which the context will be deployed host, String The context mapping to use, "" for root context. contextPath, String Base directory for the context, for static files. Must exist and be an absolute path. docBase, LifecycleListener Custom context configuration helper. Any configuration will be in addition to equivalent of
the default web.xml configuration described above. config)This is equivalent to adding a web application to a Host's appBase (usually Tomcat's webapps directory). |
| private Context | |
| protected Realm | |
| public void | |
| public void | |
| public Connector | Returns: The connector objectGet the default HTTP connector that is used by the embedded Tomcat. |
| public LifecycleListener | Returns: a listener object that configures default JSP processing.Return a listener that provides the required configuration items for JSP processing. |
| public Engine | |
| public Host | |
| private String | |
| public Server | |
| public Service | |
| protected URL | |
| private URL | |
| private URL | |
| public void | init(ConfigurationSource
The configuration source source)Initialize the server given the specified configuration source. |
| public void | init(ConfigurationSource
The configuration source source, String[] The arguments that should be passed to Catalina catalinaArguments)Initialize the server given the specified configuration source. |
| public void | |
| protected void | |
| public void | initWebappDefaults(String
The path of the context to set the defaults for contextPath)Provide default configuration for a context. |
| public static void | initWebappDefaults(Context
The context to set the defaults for ctx)Static version of |
| public static void | |
| public String | Returns: a pathname to pass toContextConfig#setDefaultWebXml(String) when using
getDefaultWebXmlListener().
|
| public void | setAddDefaultWebXmlToWebapp(boolean
false will prevent the class from automatically adding the default
settings when calling addWebapp(). true will add the default
settings and is the default behavior.By default, when calling addWebapp() to create a Context, the settings from from the default web.xml are added to the context. |
| public void | setBaseDir(String
The Tomcat base folder on which all others will be derived basedir)Tomcat requires that the base directory is set because the defaults for a number of other locations, such as the work directory, are derived from the base directory. |
| public void | setConnector(Connector
The connector instance to add connector)Set the specified connector in the service, if it is not already present. |
| public void | |
| public void | setHostname(String
The default host name s)The the hostname of the default host, default is 'localhost'. |
| public void | |
| public void | setSilent(boolean
true sets the log level to WARN for the loggers that log information on Tomcat start
up. This prevents the usual startup information being logged. false sets the log
level to the default level of INFO.Controls if the loggers will be silenced or not. |
| private void | |
| public void | |
| public void |