maven集成tomcat插件发布web项目

tomcat用户及相关权限的配置

在tomcat安装路径下找到conf/tomcat-users.xml配置文件,添加manager权限的用户,具体配置如下:

<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="tomcat" password="tomcat" 
        roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/> 
</tomcat-users>

Maven的server配置

在Maven的安装路径找到conf目录下的settings.xml文件,如图所示:

image

在servers节点中添加tomcat7下配置的用户信息(id可以任意填写,但username和password必须和步骤1一致),具体配置如下:

    <!--注意:这里的用户名和密码必须与上诉中配置的用户名和密码一致-->
    <servers>
        <server>
           <id>tomcat7</id>
           <username>tomcat</username>
           <password>tomcat</password>
        </server>
    </servers>

pom.xml文件中的配置

<build>
    <finalName>mojie-api-web-x3zl</finalName>
    <plugins>
        <!-- 指定编译jdk为1.7 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <target>1.7</target>
                <resource>1.7</resource>
            </configuration>
        </plugin>
        <!-- tomcat7插件 -->
        <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <port>8080</port>
                    <url>http://localhost:8080/mojie-api-web-x3zl/text</url>
                    <server>tomcat7</server>
                    <username>tomcat</username>
                    <password>tomcat</password>
                    <uriEncoding>UTF-8</uriEncoding>
                    <path>/v1/web/appliance</path>
                    <contextReloadable>true</contextReloadable>
                </configuration>
            </plugin>
    </plugins>
  </build>

注意必须输入的是tomcat7 因为是根据pom.xml配置中server中的id名称而来。

以上配置好之后,可以配置启动tomcat命令,如下图所示:

image

也可以不用配置tomcat:run命令,直接通过展开maven projects的方式启动,具体步骤如下:

image

maven集成tomcat插件常见命令如下:

  • tomcat7:deploy 部署一个web war包
  • tomcat7:reload 重新加载web war包
  • tomcat7:start 启动tomcat
  • tomcat7:stop 停止tomcat
  • tomcat7:undeploy 停止一个war包
  • tomcat7:run 启动嵌入式tomcat ,并运行当前项目
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值