public class EmbeddedTomcat extends Object
| Constructor and Description |
|---|
EmbeddedTomcat()
Creates an embedded Tomcat with context path "" and port 8080.
|
EmbeddedTomcat(int port)
Creates an embedded Tomcat with context path "" and specified port.
|
EmbeddedTomcat(String contextPath)
Creates an embedded Tomcat with the specified context path and port 8080 Context directory points to current
directory + /src/main/webapp Change context directory with the method
setContextDirectory(String) |
EmbeddedTomcat(String contextPath,
int port)
Creates an embedded Tomcat with specified context path and specified port.
|
| Modifier and Type | Method and Description |
|---|---|
EmbeddedTomcat |
addContextEnvironment(org.apache.catalina.deploy.ContextEnvironment env)
Adds a
ContextEnvironment object to embedded Tomcat. |
EmbeddedTomcat |
addContextEnvironment(String name,
String value,
String type)
Convenient method for adding a context environment to the embedded Tomcat.
|
EmbeddedTomcat |
addContextEnvironmentAndResourceFromFile(File contextFile)
Deprecated.
|
EmbeddedTomcat |
addContextEnvironmentAndResourceFromFile(String contextFile)
Deprecated.
|
EmbeddedTomcat |
addContextEnvironmentString(String name,
String value)
Convenient method for adding a context environment with type java.lang.String to the embedded Tomcat.
|
EmbeddedTomcat |
addContextInitializationParameter(String name,
String value) |
EmbeddedTomcat |
addContextResource(org.apache.catalina.deploy.ContextResource res)
Adds a
ContextResource object to the list of resources in the embedded Tomcat. |
EmbeddedTomcat |
addDefaultListeners()
Installs the default listeners AprLifecycleListener, JasperListener, JreMemoryLeakPreventionListener,
GlobalResourcesLifecycleListener and ThreadLocalLeakPreventionListener during startup.
|
static EmbeddedTomcat |
create()
Convenient method to create a embedded Tomcat that listens on port 8080 and with a context path of ""
|
EmbeddedTomcat |
dontAddShutdownHook()
The EmbeddedTomcat listens per default for shutdown commands on port 8005 with the shutdown command
SHUTDOWN. |
EmbeddedTomcat |
enableCompression(int compressionMinSize,
String compressableMimeType) |
EmbeddedTomcat |
enableNaming()
Enables JNDI naming which is disabled by default.
|
static void |
main(String[] args)
Starts a embedded Tomcat on port 8080 with context path "" and context directory current directory +
/src/main/webapp
|
EmbeddedTomcat |
setContextDirectory(String contextDirectory)
Sets the context directory.
|
EmbeddedTomcat |
setContextFile(String contextFile)
Sets the location of the context file that configures this web application
|
EmbeddedTomcat |
setContextFile(URL contextFileURL)
Sets the location of the context file that configures this web application
|
EmbeddedTomcat |
setContextPath(String contextPath)
Sets the contextPath for the webapplication
|
EmbeddedTomcat |
setPort(int port)
Sets the port the server is listening for http requests
|
EmbeddedTomcat |
setPrivileged(boolean privileged)
Set the privileged flag for this web application.
|
EmbeddedTomcat |
setSecondsToWaitBeforePortBecomesAvailable(int seconds)
Before starting the embedded Tomcat the programm tries to stop a previous process by sendig the shutdown command
to the shutdown port.
|
EmbeddedTomcat |
setShutdownPort(int shutdownPort)
Specifies the port the server is listen for the shutdown command.
|
EmbeddedTomcat |
setSilent(boolean silent)
Set the silent flag of Tomcat.
|
EmbeddedTomcat |
setTempDirectory(File tempDirectory)
Sets the location of the temporary directory.
|
EmbeddedTomcat |
setTempDirectoryName(String name)
Sets the temporary directory to a directory beneath the target directory
The directory does not have to exists, Tomcat will create it automatically if necessary. |
EmbeddedTomcat |
skipJarsContextConfig(String skipJars)
Additional JARs (over and above the default JARs set with
skipJarsDefaultJarScanner(String)) to skip
when scanning for Servlet 3.0 pluggability features. |
EmbeddedTomcat |
skipJarsDefaultJarScanner(String skipJars)
List of JAR files that should not be scanned using the JarScanner functionality.
|
EmbeddedTomcat |
skipJarsTldConfig(String skipJars)
Additional JARs (over and above the default JARs set with
skipJarsDefaultJarScanner(String)) to skip
when scanning for TLDs. |
void |
start()
Starts the embedded Tomcat and do not wait for incoming requests.
|
void |
startAndWait()
Starts the embedded Tomcat and waits for incoming requests.
|
void |
stop()
Stops the embedded tomcat.
|
EmbeddedTomcat |
useNio()
Instructs the embedded tomcat to use the Non Blocking Connector (org.apache.coyote.http11.Http11NioProtocol)
instead of the Blocking Connector (org.apache.coyote.http11.Http11Protocol)
|
public EmbeddedTomcat()
setContextDirectory(String)setContextDirectory(String)public EmbeddedTomcat(int port)
setContextDirectory(String)port - ip port the server is listeningsetContextDirectory(String)public EmbeddedTomcat(String contextPath)
setContextDirectory(String)contextPath - The context path has to start with /setContextDirectory(String)public EmbeddedTomcat(String contextPath, int port)
setContextDirectory(String)contextPath - has to start with /port - ip port the server is listening. Shutdown port is set to port + 1000setContextDirectory(String)public static void main(String[] args)
args - program argumentspublic static EmbeddedTomcat create()
public EmbeddedTomcat setPort(int port)
port - The new portpublic EmbeddedTomcat setContextPath(String contextPath)
contextPath - The new contextPath. Has to start with / or is the empty "" stringpublic EmbeddedTomcat setContextDirectory(String contextDirectory)
contextDirectory - Path name to the directory that contains the web application.public EmbeddedTomcat skipJarsDefaultJarScanner(String skipJars)
Scan specific lists (to exclude JARs from individual scans) see skipJarsContextConfig(String) and
skipJarsTldConfig(String).
The list must be a comma separated list of JAR file names. Example: spring*.jar,cglib*.jar.
This list is appended to the default list. The default list is located in the file CATALINA_HOME\conf\catalina.properties under the key tomcat.util.scan.DefaultJarScanner.jarsToSkip
skipJars - list of jars, comma separatedpublic EmbeddedTomcat skipJarsContextConfig(String skipJars)
skipJarsDefaultJarScanner(String)) to skip
when scanning for Servlet 3.0 pluggability features. These features include web fragments, annotations, SCIs and
classes that match @HandlesTypes. The list must be a comma separated list of JAR file names.skipJars - list of jars, comma separatedpublic EmbeddedTomcat skipJarsTldConfig(String skipJars)
skipJarsDefaultJarScanner(String)) to skip
when scanning for TLDs. The list must be a comma separated list of JAR file names.skipJars - list of jars, comma separatedpublic EmbeddedTomcat setTempDirectory(File tempDirectory)
target/tomcat. + port
tempDirectory - File object that represents the location of the temp directorypublic EmbeddedTomcat setTempDirectoryName(String name)
name - directory namesetTempDirectory(File)public EmbeddedTomcat dontAddShutdownHook()
SHUTDOWN. Calling this method disables adding the shutdown hook.public EmbeddedTomcat setSecondsToWaitBeforePortBecomesAvailable(int seconds)
seconds - number of secondspublic EmbeddedTomcat setShutdownPort(int shutdownPort)
shutdownPort - the shutdown portdontAddShutdownHook()public EmbeddedTomcat setPrivileged(boolean privileged)
privileged - The new privileged flagpublic EmbeddedTomcat useNio()
public EmbeddedTomcat enableCompression(int compressionMinSize, String compressableMimeType)
public EmbeddedTomcat enableNaming()
public EmbeddedTomcat addDefaultListeners()
public EmbeddedTomcat setSilent(boolean silent)
silent - The new silent flagpublic EmbeddedTomcat addContextEnvironment(org.apache.catalina.deploy.ContextEnvironment env)
ContextEnvironment object to embedded Tomcat.
Example:
Tomcat context xml file
<Environment name="aparam"
value="test"
type="java.lang.String"
override="false"/>
A programmatic way to add this environment to the embedded Tomcat is by calling this method
ContextEnvironment env = new ContextEnvironment();
env.setType("java.lang.String");
env.setName("aparam");
env.setValue("test");
embeddedTomcat.addContextEnvironment(env);
env - context environment variableContextEnvironment,
NamingResources.addEnvironment(ContextEnvironment),
addContextEnvironment(String, String, String),
addContextEnvironmentString(String, String)public EmbeddedTomcat addContextResource(org.apache.catalina.deploy.ContextResource res)
ContextResource object to the list of resources in the embedded Tomcat.
Example:
Tomcat context xml file
<Resource name="jdbc/ds" auth="Container"
type="javax.sql.DataSource" username="sa" password=""
driverClassName="org.h2.Driver"
url="jdbc:h2:~/mydb"
maxActive="20" maxIdle="4" maxWait="10000"
defaultAutoCommit="false"/>
Programmatic way:
ContextResource res = new ContextResource();
res.setName("jdbc/ds");
res.setType("javax.sql.DataSource");
res.setAuth("Container");
res.setProperty("username", "sa");
res.setProperty("password", "");
res.setProperty("driverClassName", "org.h2.Driver");
res.setProperty("url", "jdbc:h2:˜/mydb");
res.setProperty("maxActive", "20");
res.setProperty("maxIdle", "4");
res.setProperty("maxWait", "10000");
res.setProperty("defaultAutoCommit", "false");
embeddedTomcat.addContextResource(res);
res - resource objectContextResource,
NamingResources.addResource(ContextResource)public EmbeddedTomcat addContextInitializationParameter(String name, String value)
public EmbeddedTomcat addContextEnvironment(String name, String value, String type)
ContextEnvironment object and adds it to the list of the context environments.
Example:
Tomcat context xml file
<Environment name="aparam"
value="test"
type="java.lang.String"
override="false"/>
Programmatic way:
embeddedTomcat.addContextEnvironment("aparam", "test", "java.lang.String");
name - name of the context environmentvalue - value of the context environmenttype - type of the context environmentContextEnvironment,
NamingResources.addEnvironment(ContextEnvironment),
addContextEnvironment(ContextEnvironment),
addContextEnvironmentString(String, String)public EmbeddedTomcat addContextEnvironmentString(String name, String value)
embeddedTomcat.addContextEnvironment("aparam", "test");
name - name of the context environmentvalue - value of the context environmentContextEnvironment,
NamingResources.addEnvironment(ContextEnvironment),
addContextEnvironment(ContextEnvironment),
addContextEnvironment(String, String, String)@Deprecated public EmbeddedTomcat addContextEnvironmentAndResourceFromFile(File contextFile)
setContextFile(URL)contextFile - Location of the context filepublic EmbeddedTomcat setContextFile(URL contextFileURL)
contextFileURL - Location of the context filepublic EmbeddedTomcat setContextFile(String contextFile)
contextFile - Location of the context file@Deprecated public EmbeddedTomcat addContextEnvironmentAndResourceFromFile(String contextFile)
setContextFile(String)contextFile - Location to a context filepublic void start()
startAndWait()public void startAndWait()
start()public void stop()
Copyright © 2012–2014. All rights reserved.