How do I redeploy a maven web application to Tomcat?
Author: Deron Eriksson
Description: This tutorial describes how to redeploy a maven web application to Tomcat using the maven tomcat plugin.
Tutorial created using:
Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1) || Tomcat 6.0.14
In another tutorial, we saw how we could perform a "mvn tomcat:deploy" command to build and deploy a mavenSW project to TomcatSW using the maven tomcatSW plugin. If we have already deployed the warW file to Tomcat and we try to deploy it again using "mvn tomcat:deploy", we'll see an error similar to the following: Fragment of console output from performing "mvn tomcat:deploy" for a web application that is currently deployed.... [INFO] [tomcat:deploy] [INFO] Deploying war to http://192.168.1.7:8080/mywebapp [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Cannot invoke Tomcat manager: FAIL - Application already exists at path /mywebapp ... One way that we can redeploy a project to Tomcat is to perform a "tomcat:undeploy" command followed by a "tomcat:deploy" command. So, we could perform a maven command such as: mvn clean tomcat:undeploy tomcat:deploy This command will clean the project, then undeploy the project from Tomcat, and then build and deploy the project to Tomcat. If I execute this maven command on the "mywebapp" maven web application project, I receive the following console output: Console output from 'mvn clean tomcat:undeploy tomcat:deploy'[INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'tomcat'. [INFO] ------------------------------------------------------------------------ [INFO] Building mywebapp Maven Webapp [INFO] task-segment: [clean, tomcat:undeploy, tomcat:deploy] [INFO] ------------------------------------------------------------------------ [INFO] [clean:clean] [INFO] Deleting directory C:\dev\workspace\mywebapp\target [INFO] [tomcat:undeploy] [INFO] Undeploying application at http://192.168.1.7:8080/mywebapp [INFO] OK - Undeployed application at context path /mywebapp [INFO] Preparing tomcat:deploy [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to C:\dev\workspace\mywebapp\target\classes [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] No sources to compile [INFO] [surefire:test] [INFO] No tests to run. [INFO] [war:war] [INFO] Packaging webapp [INFO] Assembling webapp[mywebapp] in [C:\dev\workspace\mywebapp\target\mywebapp] [INFO] Processing war project [INFO] Webapp assembled in[73 msecs] [INFO] Building war: C:\dev\workspace\mywebapp\target\mywebapp.war [INFO] [tomcat:deploy] [INFO] Deploying war to http://192.168.1.7:8080/mywebapp [INFO] OK - Deployed application at context path /mywebapp [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5 seconds [INFO] Finished at: Wed Feb 06 13:25:32 PST 2008 [INFO] Final Memory: 10M/19M [INFO] ------------------------------------------------------------------------ (Continued on page 2) Related Tutorials:
|