1、配置tomcat-users.xml文件

在tomcat安装目录下找到tomcat-users.xml文件。该文件路径为【tomcat安装根目录】/conf/

修改文件内容,增加下列内容:(一般配置后两个角色就行了)

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

  

启动tomcat7,然后访问http://localhost/manager/html,输入tomcat/tomcat,如果出现以下界面,表示tomcat一切OK

如果是Tomcat6 http://localhost/manager

2、配置maven 的setting.xml 文件

在Maven的conf目录中的setting.xml servers节点增加

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

3、配置项目pom.xml文件(下面将端口改为80的配置)

            <!-- tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost/manager/text</url>
<server>tomcat7</server>
<username>tomcat</username>
<password>tomcat</password>
<port>80</port>
<path>/blog</path>
</configuration>
</plugin>

注:此处的url 注意是xxx/manager/text 并非是 xxx/manager/html 原因是我用的tomcat 是tomcat7 的版本

4、cmd运行

先进入到项目所在的目录,然后运行

mvn tomcat:redeploy

 

 

最终结果:

其中只有system-web是web项目,其它都不是,只是一些依赖项目

在目录D:\Java\Tool\apache-tomcat-7.0.62\webapps可以找到发布好的文件

第二种:

Eclipse中发布项目:

刚才那个界面会部署上blog

浏览器输入:http://localhost/blog

常见错误排除:

1.Connection refused错误

报错信息如下:

[ERROR]Failed to execute goal org.apache.tomcat.maven: tomcat7-maven-plugin: 2.0- SNAPSHOT: deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Connection refused: connect -> [Help 1]  

原因:未启动Tomcat服务器

解决办法:先启动Tomcat服务器再选择Run

2. 401错误

报错信息如下:

[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin: 2.0-SNAPSHOT:deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/text/deploy?path=%2Fhelloworld -> [Help 1]  

原因:权限问题

解决办法在$CATALINA_BASE/conf/tomcat-users.xml,

如D:\apache-tomcat-7.0.34\conf\tomcat-users.xml文件中添加权限

修改pom.xml文件,在<configuration>  </configuration>中添加

3.403错误

报错信息如下:

[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin: 2.0-SNAPSHOT:deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/html/deploy?path=%2Fhelloworld -> [Help 1]  

原因:产生该问题有可能因为两个原因,具体参见解决办法

解决办法:

1)如果使用的是Tomcat 7,需要修改pom.xml中部署的url地址,将

<url>http://localhost/manager</url>

<url>http://localhost/manager/text</url>

在这次部署的问题上,我就是遇到了url 的问题,我用的是tomcat7

2)给tomcat用户权限分配上,需要同时具备manager-gui和manager-script权限

正确的conf/tomcat-users.xml配置应为:

Maven 集成Tomcat7插件自动部署的更多相关文章

  1. Maven 集成Tomcat7插件

    Maven已经是Java的项目管理标配,如何在JavaEE开发使用Maven调用Web应用,是很多同学关心的问题.本文将介绍,Maven如何介绍Tomcat插件. Maven Tomcat插件现在主要 ...

  2. Maven集成Tomcat插件

    目录 类似插件及版本区别: 本地运行,启动嵌入式tomcat: 错误一: 错误二: Idea运行调试: vscode运行调试: 远程部署: 项目中的pom.xml配置: Tomcat中的tomcat- ...

  3. 使用jenkins 插件自动部署项目至tomcat

    前面使用maven.ant编译项目就不说,只说一下使用jenkins的插件自动部署项目 1.首先jenkins安装插件Deploy to container Plugin ,下载地址为:https:/ ...

  4. Intellij IDEA集成mybatis-generator插件自动生成数据库实体操作类

    Intellij IDEA集成mybatis-generator插件自动生成数据库实体操作类 转载至:https://blog.csdn.net/fishinhouse/article/details ...

  5. IDEA maven使用tomcat7插件启动报错:A child container failed during start

    使用maven的tomcat7插件启动项目时出现上面的错误:A child container failed during start, 出现这个问题的原因是导入了servlet-api包,与tomc ...

  6. 持续集成之Jenkins自动部署war包到远程服务器

    一.无war包链接的情况 无war包链接时,需先下载war包到本地,然后执行: ---------------------------------------------以下部分为转载-------- ...

  7. 【IDEA】IDEA集成Tomcat7插件运行项目

    Maven已经是Java的项目管理标配,如何在JavaEE开发使用Maven调用Web应用,是很多同学关心的问题.本文将介绍,Maven如何介绍Tomcat插件. Maven Tomcat插件现在主要 ...

  8. jenkins maven git windows code 自动部署

    本人刚刚接触  写的不好就对付看看吧 哈哈哈O(∩_∩)O哈哈~ 最近看见别人弄得自动部署 自己也是手痒痒 也想弄一个 所以就弄了一个 windows的 我用的是https的  在网上看了很多都是 s ...

  9. 使用maven插件自动部署web应用至Docker容器的tomcat

    配置maven 在pom.xml加入 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 <plugins>     <plugin>         <gr ...

随机推荐

  1. django+xadmin在线教育平台(一)

    大家好,此教程为在慕学网的实战教程Python升级3.6 强力Django+杀手级Xadmin打造在线教育平台的学习笔记,不对望指正! 使用Django+Xadmin打造在线教育平台(Python2, ...

  2. HDU 1423 Greatest Common Increasing Subsequence(LCIS)

    Greatest Common Increasing Subsequenc Problem Description This is a problem from ZOJ 2432.To make it ...

  3. 第15课 栏目的排序处理(组件化) Thinkphp5商城第四季

    目录 要实现的功能 思路: 视图层 控制器里: 扩展函数里 要实现的功能 用表单里的提交过来的sort数据,批量修改表里的排序值 界面效果: 思路: 视图层表单提交数据主键=>sort值 控制器 ...

  4. 面试前赶紧看了5道Python Web面试题,Python面试题No17

    目录 本面试题题库,由公号:非本科程序员 整理发布 第1题: Flask中的请求上下文和应用上下文是什么? 第2题:django中间件的使用? 第3题: django开发中数据做过什么优化? 第4题: ...

  5. Java Web 基础(一) 基于TCP的Socket网络编程

    一.Socket简单介绍 Socket通信作为Java网络通讯的基础内容,集中了异常.I/O流模式等众多知识点.学习Socket通信,既能够了解真正的网络通讯原理,也能够增强对I/O流模式的理解. 1 ...

  6. 5分钟带你快速理解Http协议

    HTTP协议 什么是HTTP协议 HTTP(Hyper Text Transfer Protocol)协议又叫超文本传输协议,是建立在TCP/IP协议之上的用来传递数据的协议.它不涉及数据包的传递,主 ...

  7. 802. Find Eventual Safe States

    https://leetcode.com/problems/find-eventual-safe-states/description/ class Solution { public: vector ...

  8. 栈及其DFS:B - Parentheses Balance

    解题心得及总结: 总结: 1.递推:又1推出n,数列中的基本到通项,最终目标得出通项公式. 递归:又n先压缩栈到1,再从函数的出口找到1,又1到n,再从n计算到1: 2.判断是否可以由递推或递推得出, ...

  9. German Collegiate Programming Contest 2018​ C. Coolest Ski Route

    John loves winter. Every skiing season he goes heli-skiing with his friends. To do so, they rent a h ...

  10. #3 working with data stored in files && securing your application (PART II)

    Security problems is more and more important on the internet today. You can see the problems . This ...