This article will explain on how to deploy a war fine in to Tomcat 7 through maven build.

Note : I have tested same settings for Tomcat 8 as well. So below settings can be apply for both versions.

Configure tomcat7-maven-plugin in pom.xml

    <!-- Tomcat plugin -->  
            <plugin>  
                 <groupId>org.apache.tomcat.maven</groupId>  
                 <artifactId>tomcat7-maven-plugin</artifactId>  
                 <version>2.2</version>  
                 <configuration>  
                 <!-- finalName:defaults to ${artifactId}-${version} -->
                  <path>/beepay</path>  
                  <update>true</update>  
                  <url>http://localhost:8080/manager/text</url>
                  <server>Tomcat</server>  
                  <username>tomcat</username>  
                  <password>tomcatuser</password>  
                 </configuration>  
            </plugin> 

Configure user rights in the tomcat-user.xml which is in the tomcat conf file.

<role rolename="tomcat" />  
<role rolename="manager-gui" />  
<role rolename="manager-script" />  
<role rolename="admin-gui" />  
<user username="tomcat" password="tomcatuser"  
 roles="tomcat,manager-gui,admin-gui,manager-script" /> 

Adding server to Maven settings.xml file: Next step is to add a server in maven settings.xml file, as shown below.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
      <server>
        <id>Tomcat</id>
        <username>tomcat</username>
        <password>tomcatuser</password>
      </server>
</servers>
</settings>

overwrite the tomcat-users.xml to eclipse server folder :Project Explorer > 'Server's > Tomcat v7.0 Server at localhost-config > tomcat-users.xml

change  default deployment  path to:

add a mvn goal:

 

 

posted on 2015-09-13 02:46  七月逆流  阅读(387)  评论(0编辑  收藏  举报