本篇内容主要讲解“maven怎么发布war包到tomcat中”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“maven怎么发布war包到tomcat中”吧!
先在本地将代码打成 war 包,然后调用tomcat的接口 *
${host}/manager/text
接口将war包上传到tomcat的webapp
*目录下,重启tomcat即可
配置tomcat权限,使可以可以通过接口方式传war包
配置tomcat允许访问的ip地址
在maven的setting中配置tomcat的用户名密码等信息
在maven的pom.xml中配置maven的地址以及发布项目名称
编辑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 配置文件
${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>
tomcat
的用户名密码等信息编辑 maven 中的setting文件,在servers节点中添加一个server子节点如下:
<servers> <server> <id>tomcat-maven</id> <username>deploy</username> <password>deploy</password> </server> </servers>
编辑 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
到此,相信大家对“maven怎么发布war包到tomcat中”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。