Tomcat web-application deployment
A lab aimed to develop a "typical" solution for Spring MVC/Maven web application deployment to Tomcat 7. Requirements are:
- There should be a solution to run application locally.
- There should be a solution to configure, build and deploy application to Tomcat 7 server.
How to play with it
- Running application locally using embedded Jetty:
mvn clean jetty:run-exploded
. Because I have no idea how to make it work withjetty:run
without lots of extra stuff inpom.xml
, my solution is: first, buildwar
package and explode it, then, run exploded package with Jetty. - Deploying application to Tomcat 7 (predefined settings):
mvn clean tomcat7:redeploy -Ptomcat-deployment
- Deploying application to Tomcat 7 (Teamcity settings):
mvn clean tomcat7:redeploy -Pteamcity
. This will expect the environment to provide:
-
TOMCAT_SERVER
- server name described in Maven'ssettings.xml
. -
TOMCAT_URL
- URL of Tomcat's management application. Normally, something likehttp://localhost:8080/manager/text
. -
TOMCAT_PATH
- relative path to deploy application to. Example:/experiment
. -
ENVNAME
- used only for illustrative purposes. Can be whatever desired. -
ROOTURL
- used only for illustrative purposes. Can be whatever desired.
Environment pre-configuration
Tomcat 7 should have a user with deployment permissions. This is done by making changes to [tomcat7]/conf/tomcat-users.xml
:
<tomcat-users>
...
<user name="deployer" password="deploy123" roles="manager-script" />
...
</tomcat-users>
Deployment requires Maven to have credentials for accessing Tomcat's management service. This is done by making changes to settings.xml
:
<settings>
...
<servers>
...
<server>
<id>TomcatServer</id> <!-- It's, BTW, what `TOMCAT_SERVER` is -->
<username>deployer</username>
<password>deploy123</password>
</server>
...
</servers>
...
</settings>
Written by Andrey Agibalov
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Maven
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#