Last week I used the mvn tomcat7:redeploy command to Deploy to Tomcat with maven. This command literally invokes the redeploy action of the tomcat7 plugin. Today, I’ll tie the tomcat7 plugin into the maven lifecycle.
The maven default build lifecycle has eight phases:
- validate
- compile
- test
- package
- integration-test
- verify
- install
- deploy
I’ll bind the tomcat7:redeploy action to the install lifecycle phase. This is as simple as adding an new executions element to the plugin configuration. As shown below, the executions element includes an execution element that associates the deploy redeploy plugin goal to the install maven phase.
I’ve also updated the plugin configuration to set the path from the build.finalName. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26$ git diff Amber 6:25
diff --git a/pom.xml b/pom.xml
index 7e41e9d..0fe5b04 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,10 +27,19 @@
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
+ <executions>
+ <execution>
+ <id>tomcat7-redeploy</id>
+ <phase>install</phase>
+ <goals>
+ <goal>redeploy</goal>
+ </goals>
+ </execution>
+ </executions>
<configuration>
<url>http://xxxxxx-nnnnnn.use1-2.nitrousbox.com:8080/manager/text</url>
<server>nitrous</server>
- <path>/jersey-json</path>
+ <path>/${project.build.finalName}</path>
</configuration>
</plugin>
</plugins>
With that done, I can now deploy the webapp to tomcat with the mvn install command:
1 | $ mvn install |
Sep 28: corrected tomcat7 plugin goal from deploy to redeploy