使用Maven Cargo 插件管理Tomcat7的远程和本地部署

使用Maven Cargo 插件管理Tomcat6的部署原文: http://jdonee.iteye.com/blog/774387
参考文档:
Apache Maven Cargo deploy with Tomcat 7
http://www.waltercedric.com/index.php?option=com_content&view=article&id=1906:&catid=129&Itemid=332


tomcat-users.xml,必须存在admin账户:
<tomcat-users>
	<role rolename="tomcat"/>
	<role rolename="manager"/>	
	<role rolename="manager-script"/>
	<role rolename="manager-status"/>
	<role rolename="manager-jmx"/>	
	<role rolename="manager-gui"/>
	<role rolename="admin"/>
	<role rolename="admin-gui"/> 
	<user username="admin" password="admin" roles="admin,admin-gui,manager,manager-gui,manager-script,manager-status,manager-jmx"/>
</tomcat-users>




tomcat7远程部署: 前提,这个tomcat已经存在并运行。
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <configuration>
                    <container>
                        <containerId>tomcat7x</containerId>
                        <type>remote</type>
                    </container>
                    <configuration>
                        <type>runtime</type>
                        <properties>
                            <cargo.remote.uri>http://xxx.xxx.xxx:8080/manager/text/</cargo.remote.uri>
                            <cargo.remote.username>admin</cargo.remote.username>
                            <cargo.remote.password>admin</cargo.remote.password>
                        </properties>
                    </configuration>
                    <deployables>
                        <deployable>
                            <groupId>xxx</groupId>
                            <artifactId>yyy</artifactId>
                            <type>war</type>
                            <properties>
                                <context>/my_web_context_path</context>
                            </properties>
                        </deployable>
                    </deployables>
                </configuration>
                <executions>
                <!-- 打包的时候顺便部署-->
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <!--<goal>deployer-undeploy</goal>-->
                            <goal>deployer-redeploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

deployer是部署时的相关配置,这个context是用来声明工程部署后的上下文,也就是主机地址后面的一级目录位置。这个设置在maven构建中还是很必要的。因为maven默认打出  的war包是工程名+版本号,部署时如果不设置这里的context,那上下文就变成了工程名+版本号的形式。这会使访问变得很不方便。注意,即使你通过修改war插件中的warName也是不能达到这个 目的,因为cargo认定的默认war包名就是工程名+版本号的形式。也可以利用finalName来制定

如果配置了exceutions的话,就是maven的周期(上面是package周期)的时候出发,
命令: mvn package
否则单独运行:
mvn cargo:deployer-undeploy  //如果先存在已经部署的,就先执行这句,卸载掉原先部署的。
mvn cargo:deployer-deploy
或者直接执行
mvn cargo:deployer-redeploy

注意:
<groupId>xxx</groupId>
<artifactId>yyy</artifactId>

这里应该跟pom定义的一致,如果打包得到war的文件不是按照pom的规则来,那么可能会找不到war文件。




本地和远程部署的配置参考,未测试
本地
            <plugin>              
              <groupId>org.codehaus.cargo</groupId>  
              <artifactId>cargo-maven2-plugin</artifactId>  
              <version>1.0.6</version>  
              <configuration>  
                  <container>  
                      <containerId>tomcat6x</containerId>  
                      <home>F:\apache-tomcat-6.0.18</home>  
                  </container>  
                  <configuration>  
                      <type>existing</type>  
                      <home>F:\apache-tomcat-6.0.18</home>  
                  </configuration>  
              </configuration>  
          </plugin>  

             
远程
            <plugin>              
              <groupId>org.codehaus.cargo</groupId>  
              <artifactId>cargo-maven2-plugin</artifactId>  
              <version>1.0.6</version>  
               <configuration>  
                  <container>  
                      <containerId>tomcat6x</containerId>  
                      <type>remote </type>  
                  </container>  
                  <configuration>  
                      <type>runtime</type>  
                      <properties>  
                        <cargo.remote.username>admin</cargo.remote.username>  
                        <cargo.remote.password>admin</cargo.remote.password>  
                        <cargo.tomcat.manager.url>  
                        http://172.31.36.214:8080/manager  
                        </cargo.tomcat.manager.url>  
                        </properties>  
                  </configuration>  
              </configuration>  
                

          </plugin>

猜你喜欢

转载自panyongzheng.iteye.com/blog/1872904