maven发布war包到tomcat中

通过maven打包并发到tomcat中

原理如下:

先在本地将代码打成 war 包,然后调用tomcat的接口 *${host}/manager/text接口将war包上传到tomcat的webapp*目录下,重启tomcat即可


因此需要以下步骤

  1. 配置tomcat权限,使可以可以通过接口方式传war包
  2. 配置tomcat允许访问的ip地址
  3. 在maven的setting中配置tomcat的用户名密码等信息
  4. 在maven的pom.xml中配置maven的地址以及发布项目名称

第一步:配置tomcat权限,使可以可以通过接口方式传war包

编辑tomcat 配置文件 ${Catalina_home}/con/tomcat_users.xml,配置权限如下:

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

manager-gui 表示 允许访问html接口(即URL路径为/manager/html/) manager-script 表示 允许访问纯文本接口(即URL路径为/manager/text/)


第二步:配置tomcat允许访问的ip地址

编辑tomcat 配置文件 ${Catalina_home}/webapp/manager/META-INF/context.xml,将context节点下的*<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />*注释掉,结果如下:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<Context antiResourceLocking="false" privileged="true" >
<!--
 <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

-->
 <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

第三步:在maven的setting中配置tomcat的用户名密码等信息

编辑 maven 中的setting文件,在servers节点中添加一个server子节点如下:

<servers>
   <server>
     <id>tomcat-maven</id>
     <username>deploy</username>
     <password>deploy</password>
   </server>
 </servers>

第四步:在maven的pom.xml中配置maven的地址以及发布项目名称

编辑 maven 中的pom.xml文件,早plugins中添加plugin节点:

<plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <server>tomcat-maven</server>
                    <url>http://30.23.76.63:8080/manager/text</url>  <!--注释:该链接适用的角色为tomcat7中设置的manager-script-->
                    <path>/${finalName}</path>
                </configuration>
            </plugin>

server 必须和第三步中id的值保持一致

到目前为止配置工作已经完成,只需打包并发布即可

发布方式:只需要在maven打包命令后加上tomcat7:redeploy命令即可,如下:

mvn package -Dmaven.test.skip=true tomcat7:redeploy

转载于:https://my.oschina.net/u/2263364/blog/3085154

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值