zoukankan      html  css  js  c++  java
  • 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用户名.m2settings.xml),在节点下添加

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

    3.配置settings.xml  

    修改Maven的setting.xml(默认是C:Users用户名.m2settings.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. 查找到的会造成这个的原因有:
  • 相关阅读:
    ES6中的export,import ,export default
    centos7 安装php 多线程pthreads
    ubuntu系统安装nginx出现的错误(依赖环境没有安装完)
    ubuntu彻底干净卸载MySQL、Apache2、Php的方法(各版本通用
    mysql-ubuntu14.04彻底卸载mysql
    centos 中GTK的安装
    centos 安装cmake 3.3.2
    yum安装方式的php,切换NTS为ZTS版本
    eclipse中jad反编译工具的安装
    在SpringMVC中获取request对象的几种方式
  • 原文地址:https://www.cnblogs.com/zhaoyan001/p/8735084.html
Copyright © 2011-2022 走看看