maven发布war包到tomcat中
2020-02-02 01:15
555 查看
通过maven打包并发到tomcat中
原理如下:
先在本地将代码打成 war 包,然后调用tomcat的接口 *
${host}/manager/text接口将war包上传到tomcat的webapp*目录下,重启tomcat即可
因此需要以下步骤
- 配置tomcat权限,使可以可以通过接口方式传war包
- 配置tomcat允许访问的ip地址
- 在maven的setting中配置tomcat的用户名密码等信息
- 在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
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Maven打War包并发布TOMCAT遇到的各种问题
- Maven发布war包到Tomcat
- maven生成war包,发布到tomcat中
- Maven打包.war包发布到tomcat
- 关于在maven下使用jetty打成war包,发布到tomcat报错找不到文件问题
- maven打war包和在tomcat中发布
- linux shell脚本自动从git上拉取maven代码编译打war包并发布到tomcat
- java学习4-Maven的发布war并部署到tomcat
- Idea Spring boot+Maven 打包war 发布 外部tomcat
- maven项目打成war发布到tomcat运行
- maven 发布war包到 tomcat
- maven项目生成war包,发布tomcat服务器报错,问题解决
- Tomcat发布War包或者Maven项目
- 在Tomcat发布war包,配置数据源
- SpringBoot项目使用maven打包成war方式,部署到外部Tomcat~
- Maven 集成Tomcat插件自动发布项目到tomcat的webapps目录下
- eclipse通过maven远程发布应用到Tomcat
- MAVEN项目--从svn签出到eclipse3.7--发布到tomcat6.0(图解)
- 关于maven项目搭建并发布到linux(tomcat)
- Maven+MyEclipse 创建web工程并自动发布tomcat