使用Maven实现一键部署war到Tomcat

1. 环境

  • maven:3.2.3
  • tomcat:7.0.53
  • tomcat-maven-plugins:2.2

2. Tomcat设置

实现这个功能需要在maven中增加tomcat的访问权限,所以我们要先在中tomcat增加一个管理权限。
修改tomcat的conf/tomcat-users.xml,在<tomcat-users>下增加:

<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="myeclipse" password="myeclipse" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>

3. Maven配置

在maven的配置中添加tomcat的访问权限。
修改maven的conf/settings.xml,在<servers>中添加如下:

<server>
  <id>tomcat</id>
  <username></username>
  <password></password>
</server>

用户名密码自己设置。

4. POM配置

在项目的pom.xml中增加一个tomcat的plugin:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <url>http://localhost:8080/manager/text</url>
        <server>tomcat</server>
        <username></username>
        <password></password>
        <path>/${project.build.finalName}</path>
        <warFile>${basedir}/target/${project.build.finalName}.war</warFile>
    </configuration>
</plugin>

${project.build.finalName}可以任意修改成你需要的名称。用户名密码需要和步骤3中设置的对应。

5. 执行

mvn tomcat7:redeploy

6. Errors

暂无,持续更新

猜你喜欢

转载自blog.csdn.net/yi_Afly/article/details/46755515
今日推荐