利用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的远程地址拦截器造成的结果,默认情况下,Tomcat的Manager和Host-Manager只接受本机的请求,而要让它接受远程的请求,需要添加上面提到的manager.xml的配置
由于Tomcat的Manager可以执行项目的部署、卸载等敏感操作,如果你只想允许特定的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官网和上面的博客地址
********************************* 不积跬步无以至千里,不积小流无以成江海 *********************************