基于Maven插件实现本地Maven项目的远程部署,及远程发布遇到的错误与解决方法

利用Maven插件将本地的Maven项目实现远程部署

下载一个Tomcat,上传到Linux服务器,然后解压到指定目录【随意】

然后可以使用mv命令修改一下tomcat的目录名称,LZ就修改为apache-tomcat

当我们原始的Tomcat启动时,可以看到Tomcat的首页会有 Manager App按钮,如下图所示:

访问这个需要配置一个Tomcat的用户名和密码,就是可以访问了

具体配置:在${TOMCAT_HOME}/conf/tomcat-users.xml添加如下内容:

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

然后重启使用配置好的用户名和密码就可以访问了

因为远程发布时就在本地工程的pom文件中配置上的用户名和密码,配置如下

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.tomcat.maven</groupId>
			<artifactId>tomcat7-maven-plugin</artifactId>
			<version>2.2</version>
			<configuration>
				<!-- 发布url -->
				<url>http://192.168.174.221:8080/manager/text</url>
				<!-- 发布路径 -->
				<path>/</path>
				<uriEncoding>UTF-8</uriEncoding>
                                <!--远程Tomcat端口-->
				<port>8080</port>
				<server>tomcat</server>
				<username>tomcat</username>
				<password>123456</password>
			</configuration>
		</plugin>
	</plugins>
</build>

首先要保证远程的Tomcat已经是启动好的

配置上面好的后,按下图远程部署:

查看日志:

本地远程发布就OK了 

如果在发布中报如下错误及参考解决方法见下,因为LZ在发布到AWS上时遇见了,一并奉上:

错误一:

 

错误二:

Uploading: http://localhost:8090/manager/text/deploy?path=%2Ftest&update=true
 
[INFO] I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error
[INFO] Retrying request
Uploading: http://localhost:8090/manager/text/deploy?path=%2Ftest&update=true
 
[INFO] I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error
[INFO] Retrying request
Uploading: http://localhost:8090/manager/text/deploy?path=%2Ftest&update=true
 
[INFO] I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error
[INFO] Retrying request
Uploading: http://localhost:8090/manager/text/deploy?path=%2Ftest&update=true
 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.959 s
[INFO] Finished at: 2017-10-17T16:48:59+08:00
[INFO] Final Memory: 15M/271M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:redeploy (default-cli) on project test: Cannot invoke Tomcat manager: Connection reset by peer: socket write error -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

解决方法如下图:参考来源 https://www.cnblogs.com/xyb930826/p/5725340.html

原因:经过查询Tomcat文档后发现,这是由于Tomcat的远程地址拦截器造成的结果,默认情况下,TomcatManagerHost-Manager只接受本机的请求,而要让它接受远程的请求,需要添加上面提到的manager.xml的配置

由于TomcatManager可以执行项目的部署、卸载等敏感操作,如果你只想允许特定的IP地址访问Manager,可在上面的allow属性中设置规则。具体规则设置见下面的链接:

http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Remote_Address_Filter

问题说明:http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Configuring_Manager_Application_Access

详细参考Tomcat官网和上面的博客地址

********************************* 不积跬步无以至千里,不积小流无以成江海 *********************************

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值