After installing and configuring Tomcat, you will need to deploy web applications.
Drop-In WAR
Deploying an application to Tomcat can be as simple as dropping a WAR file inside the $CATALINA_BASE/webapps directory; this will deploy the application.
Hot Deployment
To deploy a new application, you must restart the server in order for the application to function. To fix this problem, Tomcat provides a hot deployment option, which deploys an application without the need to restart.
To enable hot deployment, the autoDeploy attribute from host tag in server.xml must be set to true. See the configuration section for an example.
Tomcat Manager
Web Application
Tomcat also comes with a manager that allows for deploying an application from the web console. To use the manager, you need to add a username and password to conf/tomcat-users.xml with role manager-gui.
<tomcat-users>
<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
</tomcat-users>
Next, access http://<host>:<port>/manager to access the web console.
URI
The Tomcat Manager also provides URI commands to upload applications. They follow this schema:
http://{host}:{port}/manager/text/{command}?{parameters}
Some examples of deploying an application using URI commands:
http://{host}:{port}/manager/text/deploy?path=/foo
The above uploads to the remote server, the war with path /foo. The war is provided as the body of the HTTP PUT.
http://{host}:{port}/manager/text/deploy?path=/foo&:/path/to/foo.war
This deploys application stored in the server directory path/to/foo.war.
Arquillian
Arquillian is an integration and functional testing platform that can be used for Java middleware testing. The main goal of Arquillian is to make tests that require a server to be as simple as writing unit tests.
You can use Arquillian Tomcat adapters to write integration/functional tests.
Arquillian Tomcat 8 adapter release is coming soon.
Maven coordinates can be found at:
http://arquillian.org/modules/arquillian-tomcat-embedded-7-container-adapter/
http://arquillian.org/modules/arquillian-tomcat-managed-7-container-adapter/
http://arquillian.org/modules/arquillian-tomcat-remote-7-container-adapter/
http://arquillian.org/modules/arquillian-tomcat-embedded-8-container-adapter/
When using the embedded adapter, Tomcat embedded dependencies are required as well.
When using the remote adapter, the Tomcat instance has to expose a remote JMX MbeanConnection.
JAVA_OPTS=”$JAVA_OPTS -Dcom.sun.management.jmxremote.port=8089 “
JAVA_OPTS=”$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false “
JAVA_OPTS=”$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false”
Maven
Maven is still one of the most used build tools and therefore Tomcat integration is available.
This integration is mainly (in addition to deploying artifacts on central) a Maven plugin.
Today, there are two plugins, tomcat-maven-plugin for Tomcat 6 and tomcat7-maven-plugin for Tomcat 7; tomcat8-maven-plugin is coming soon.
Their usage is more or less the same:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager</url>
</configuration>
</plugin>
Here are the main configurations of the Maven plugin:
Parameter |
Goal |
url |
Tomcat manager URL (to deploy/undeploy/start/stop/reload) |
server |
Use settings.xml server for authentication on Tomcat manager application |
charset |
Encoding to use to communicate with manager application |
Username/password |
Credential of the manager application |
Once these configurations are set up, the available goals are as follows:
Goal |
Description |
deploy / undeploy / redeploy |
(Un)deploys a WAR |
Exec-war / standalone-war |
Create a runnable JAR or WAR running Tomcat and your application (java -jar mytomcatapp.jar) |
run |
Start Tomcat embedded with current project deployed as dynamic project |
run-war |
Same as run, using a WAR instead of resources |
shutdown |
Stop started servers (useful if using pre-integration-test phase to start Tomcat and post-integration-test to stop it) |
Note: Often goals will exist with the "-only" suffix. For example, the deploy-only goal will not fork a Maven package lifecycle.
Each goal has further configurations, for example the “context” path within the “deploy” application goal.
You can find more details at: http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/plugin-info.html.
Java EE and Beyond
Tomcat is a Servlet container that implements the Servlet/JSP/EL specifications. If you are required to use any other Java EE specification like CDI, JPA, EJB, JAX-RS, or Bean Validation, you can integrate it by yourself (assuming you understand the perils of doing it yourself), or you can use Apache TomEE. TomEE (pronounced "Tommy") is the Java Enterprise Edition of Apache Tomcat (Tomcat + Java EE = TomEE) and is Java EE 6 Web Profile certified. It maintains the light weight and simplicity of Tomcat but with the full power of Java EE.
References
Apache Tomcat site:http://tomcat.apache.org
Tomcat server.xml: http://tomcat.apache.org/tomcat-8.0-doc/config/server.html
Tomcat Logging:http://tomcat.apache.org/tomcat-8.0-doc/logging.html
Tomcat Clustering:http://tomcat.apache.org/tomcat-8.0-doc/cluster-howto.html
Tomcat Listeners:http://tomcat.apache.org/tomcat-8.0-doc/config/listeners.html
Tomcat WebSocket:http://tomcat.apache.org/tomcat-8.0-doc/web-socket-howto.html
Tomcat Maven Plugin:http://tomcat.apache.org/maven-plugin.html
Arquillian and Tomcat:https://docs.jboss.org/author/display/ARQ/Tomcat+7.0+-+Embedded
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}