pom.xml中加入cargo的Plugin声明:
1 <plugin> 2 <groupId>org.codehaus.cargo</groupId> 3 <artifactId>cargo-maven2-plugin</artifactId> 4 <version>1.4.9</version> 5 <configuration> 6 <container> 7 <containerId>tomcat7x</containerId> 8 <type>remote</type> 9 </container> 10 <configuration> 11 <type>runtime</type> 12 <properties> 13 <cargo.remote.uri>http://192.168.128.137:8080/manager/text</cargo.remote.uri> 14 <cargo.remote.username>admin</cargo.remote.username> 15 <cargo.remote.password>admin</cargo.remote.password> 16 </properties> 17 </configuration> 18 </configuration> 19 </plugin>
With Tomcat 7, the Tomcat manager has multiple aspects to be careful about:
- Your browser by default accesses the HTML-based manager whereas CARGO needs to use the text-based manager. As a result, if you want to set the
RemotePropertySet.URI
manually, please make sure you set the URL for the text-based manager, for examplehttp://production27:8080/manager/text
- The text-based manager requires to be accessed by a user with the
manager-script
role; and by default no user has that role. As a result, please make sure you modify yourtomcat-users.xml
file to give that role to a user.
You can read more in the Tomcat documentation: http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html
意思是:
- 属性cargo.remote.uri后面必须是xxx:8080/manager/text格式
- tomcat7x的权限设置和以前不一样了。要改配置给权限。可以这么改:(不管什么权限,一股脑儿全给admin再说)
1 <role rolename="manager-gui"/> 2 <role rolename="manager-script"/> 3 <role rolename="manager-jmx"/> 4 <role rolename="manager-status"/> 5 <role rolename="admin-gui"/> 6 <user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui"/>
另外,无论是博客,还是《Maven实战》都写的是用属性cargo.tomcat.manager.url。可是我看Cargo Tomcat7x文档,甚至Cargo Tomcat6x文档里面都没有提到这个属性。我一开始就用这个属性,结果总是报错,说什么Connection refused。但在这两个文档文档最下面 For remote container o.c.c.c.tomcat.Tomcat7xRemoteContainer 一栏反而有个cargo.remote.uri属性,看名字好像是一个远程uri,我试了试,竟然成功远程部署了。
所以。。。还是文档比较重要。
https://codehaus-cargo.github.io/cargo/Home.html 里面有好多容器的cargo设置。
最后,你得先保证tomcat7x是运行状态的。用
mvn cargo:redeploy 命令部署就好了。
cargo的所有goals:(具体运用中自己看吧。。。)
Goals |
Description |
---|---|
cargo:start
|
Start a container. That goal will:
Note: A container that‘s started with |
cargo:run
|
Start a container and wait for the user to press CTRL + C to stop. That goal will:
|
cargo:stop
|
Stop a container. |
cargo:restart
|
Stop and start again a container. If the container was not running before calling cargo:restart , it will simply be started. |
cargo:configure
|
Create the configuration for a local container, without starting it. Note that the cargo:start and cargo:run goals will also install the container automatically (but will not call cargo:install ).
|
cargo:package
|
Package the local container. |
cargo:daemon-start |
Start a container via the daemon. Read more on: Cargo Daemon Note: The |
cargo:daemon-stop |
Stop a container via the daemon. Read more on: Cargo Daemon |
cargo:deployer-deploy (aliased to cargo:deploy )
|
Deploy a deployable to a running container. Note: The |
cargo:deployer-undeploy (aliased to cargo:undeploy )
|
Undeploy a deployable from a running container. |
cargo:deployer-start
|
Start a deployable already installed in a running container. |
cargo:deployer-stop
|
Stop a deployed deployable without undeploying it. |
cargo:deployer-redeploy (aliased to cargo:redeploy )
|
Undeploy and deploy again a deployable. If the deployable was not deployed before calling cargo:deployer-redeploy (or its alias cargo:redeploy ) it will simply be deployed.
|
cargo:uberwar
|
Merge several WAR files into one. |
cargo:install
|
Installs a container distribution on the file system. Note that the cargo:start goal will also install the container automatically (but will not call cargo:install ).
|
cargo:help
|
Get help (list of available goals, available options, etc.). |