Maven Tomcat7+ 实现自动化部署

首先在Tomcat里配置deploy的用户(tomcat根目录/conf/tomcat-users.xml):

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

2.配置maven setting.xml

修改Maven的setting.xml(默认是C:\Users\用户名.m2\settings.xml),在节点下添加

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

3.配置settings.xml  

修改Maven的setting.xml(默认是C:\Users\用户名.m2\settings.xml),在节点下添加

<plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <url>http://127.0.0.1:8080/manager/text</url>
                    <server>tomcat7</server>
                    <path>/ROOT</path>
                    <charset>utf8</charset>
                    <update>true</update>
                </configuration>
            </plugin>
finalName>webx_0100_helloworld</finalName>
    <plugins>
        <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、username、password对应maven的setting下的配置 -->
                <server>tomcat7</server>
                <path>/${project.build.finalName}</path>
                <!-- war文件路径缺省情况下指向target -->
                <!--<warFile>${basedir}/target/${project.build.finalName}.war</warFile>-->
            </configuration>
</plugin>
<!-- 添加相关依赖 -->   
   <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-servlet-api</artifactId>
            <version>8.5.4</version>
        </dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- 移除嵌入式tomcat插件 -->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

 

4.执行部署命令

//这里我要求先重新打包,并跳过测试,再部署
//第一次
mvn package  -Pdevelop -Dmaven.skip.test=true tomcat7:deploy

//之后
mvn package  -Pdevelop -Dmaven.skip.test=true tomcat7:redeploy

注意:一开始一直报错

[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:
redeploy (default-cli) on project webx_0100_helloworld: Cannot invoke Tomcat man
ager: Connection reset by peer: socket write error -> [Help 1]
  1. 查找到的会造成这个的原因有:
posted @ 2018-04-07 21:43  程序猿001  阅读(812)  评论(0编辑  收藏  举报