使用cargo自动化部署maven项目

来源:互联网 发布:elle淘宝代购真的吗 编辑:程序博客网 时间:2024/05/17 02:56

1.在开发的过程中,将程序打包丢到服务器上,然后重启tomcat还是比较麻烦的。

我自己要做如下步骤:

1),使用maven 命令打包

2),将包通过fileZilla丢到服务器tomcat/webapps下

3),bin/shutdown.sh

4),bin/startup.sh


2.在《maven实战》一书中提到了cargo,使用这个就能够实现自动化部署。然而把上面的代码对着敲好像并没有用


3.于是自己上网查资料测试。

先介绍一下我这里的环境,tomcat8x,而网上的多数是tomcat6,所以去官网找:点击打开链接

点开后看到左边栏目中有tomcat8,就点这个。

进入后找到containerId:



再拉到最下面,看到提示:



所以就把uri设置为....../manager/text

再去编辑目标服务器的tomcat的 conf/tomcat-users.xml文件


最后文件如下:

<?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.--><tomcat-users xmlns="http://tomcat.apache.org/xml"              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"              version="1.0"><!--  NOTE:  By default, no user is included in the "manager-gui" role required  to operate the "/manager/html" web application.  If you wish to use this app,  you must define such a user - the username and password are arbitrary.--><!--  NOTE:  The sample user and role entries below are wrapped in a comment  and thus are ignored when reading this file. Do not forget to remove  <!.. ..> that surrounds them.--><role rolename="manager-gui"/><role rolename="manager-script"/><role rolename="manager-jmx"/><role rolename="manager-status"/><role rolename="admin-gui"/><user username="admin" password="password" roles="admin-gui,manager-gui,manager-script,manager-status"/></tomcat-users>



再贴一下pom.xml文件中plugin段的代码


<plugin>              <groupId>org.codehaus.cargo</groupId>              <artifactId>cargo-maven2-plugin</artifactId>              <version>1.4.16<version>              <configuration>                  <container>                      <containerId>tomcat8x</containerId>                      <type>remote<type>                  </container>                  <configuration>                      <type>runtime<type>                      <properties>                          <cargo.remote.uri>http://192.168.199.158:8080/manager/text</cargo.remote.uri>                          <cargo.remote.username>admin</cargo.remote.username>                          <cargo.remote.password>password</cargo.remote.password>                      </properties>                  </configuration>              </configuration>          </plugin>


这里解释一下:

pom.xml中的username,password 与tomcat配置中设置的要一致。

然后pom.xml中的url就是目的主机的Url,后面加上manager/text就行


最后,执行  mvn cargo:redeploy


4.之前犯的错误

之前以为原理就是远程连接到目的主机,然后把文件传过去,再重启tomcat。

于是我就在做之前先调通客户机与目的主机之间的ssh连接,用的当然是操作系统的 username以及password,所以在配置的时候username,password就不对了


直到仔细看了tomcat配置文件的修改后才发现要的是tomcat的密码,那么原理应该是这样的:访问tomcat的manager,听这个名字就知道,通过它来管理文件的传输啊,部署啊什么的,根本用不到操作系统的用户名和密码


最后贴一下成功的tomcat日志


0 0
原创粉丝点击