- Update
~/.m2/settings.xml
<settings>
<servers>
<server>
<id>dev-tomcat</id>
<username>tomcat</username>
<password>password</password>
</server>
</servers>
</settings>
- Add the following to
pom.xml
<build>
.....
<finalName>my-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<url>http://localhost:8080/manager/html</url>
<server>dev-tomcat</server>
<path>/${project.build.finalName}</path>
</configuration>
</plugin>
</plugins>
</build>
Here dev-server
refers to the <server><id>dev-tomcat</id>
defined in ~/.m2/settings.xml
Alternatively you can add the <username>
and <password>
under <configuration>
in the pom.xml
- A tomcat user must be defined in
<CATALINA_HOME>/conf/tomcat-users.xml
with the rolemanager-script
<role rolename="manager-script"/>
<user username="tomcat" password="tomcat" roles="manager-script"/>
````
4) To deploy to tomcat run: ```mvn tomcat7:deploy```
5) If your maven project has multiple modules such as below:
````
my-maven-project
|--my-app
-- pom.xml
|--my-webapp
-- pom.xml
-- pom.xml
````
The outermost pom.xml file should have at least the plugin reference:
````xml
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
````
While the ```my-webapp/pom.xml``` producing the WAR file should have ``<configuration>`` element containing url, server and path child elements:
````xml
<configuration>
<update>true</update>
<url>http://localhost:8080/manager/text</url>
<server>dev-tomcat</server>
<path>/${project.build.finalName}</path>
</configuration>
````
No comments:
Post a Comment