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 |
addAllDependenciesAsResourceJar()
Adds all the dependencies specified in the pom.xml (except scope provided)
to the context as a resource jar.
|
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)
Read ContextEnvironment and ContextResource definition from a
text file.
|
EmbeddedTomcat |
addContextEnvironmentAndResourceFromFile(String contextFile)
Read ContextEnvironment and ContextResource definition from a
text file.
|
EmbeddedTomcat |
addContextEnvironmentString(String name,
String value)
Convenient method for adding a context environment with
type java.lang.String to the embedded Tomcat.
|
EmbeddedTomcat |
addContextResource(org.apache.catalina.deploy.ContextResource res)
Adds a
ContextResource object to the list of resources
in the embedded Tomcat. |
EmbeddedTomcat |
addDependencyAsResourceJar(String groupId,
String artifact)
Adds the specified jar to the context as a resource jar.
|
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 opens as default a shutdown port on port + 1000
with the shutdown command
EMBEDDED_TC_SHUTDOWN
Calling this method disables adding the shutdown hook. |
static void |
main(String[] args)
Starts a embedded Tomcat on port 8080 with context path "/"
and context directory current directory + /src/main/webapp
|
EmbeddedTomcat |
removeDefaultServlet()
Calling this method prevents adding the DefaultServlet to the context.
|
EmbeddedTomcat |
setContextDirectory(String contextDirectory)
Sets the context directory.
|
EmbeddedTomcat |
setContextPath(String contextPath)
Sets the contextPath for the webapplication
|
EmbeddedTomcat |
setM2Directory(File m2Directory)
Sets the path to the Maven local repository.
|
EmbeddedTomcat |
setPomFile(File pomFile)
Sets the location of the pom file.
|
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. |
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.
|
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 listeningsetContextDirectory(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 /public EmbeddedTomcat setContextDirectory(String contextDirectory)
contextDirectory - Path name to the directory that contains the
web application.public 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 setPomFile(File pomFile)
pomFile - File object that points to the maven pom file (pom.xml)public EmbeddedTomcat setM2Directory(File m2Directory)
System.getProperty("user.home") + /.m2/repository/
m2Directory - File object that points to the Maven local repository directorypublic EmbeddedTomcat removeDefaultServlet()
public EmbeddedTomcat dontAddShutdownHook()
EMBEDDED_TC_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 setSilent(boolean silent)
silent - The new silent flagpublic EmbeddedTomcat addAllDependenciesAsResourceJar()
Context.addResourceJarUrl(URL)public EmbeddedTomcat addDependencyAsResourceJar(String groupId, String artifact)
groupId - the maven groupId nameartifact - the maven artifact nameContext.addResourceJarUrl(URL),
addAllDependenciesAsResourceJar()public 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 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)public EmbeddedTomcat addContextEnvironmentAndResourceFromFile(File contextFile)
contextFile - Location to a context filepublic EmbeddedTomcat addContextEnvironmentAndResourceFromFile(String contextFile)
contextFile - Location to a context filepublic void start()
startAndWait()public void startAndWait()
start()public void stop()
Copyright © 2012. All Rights Reserved.