Recently, I took over several Tomcat web applets. Every time the function goes online, it has to be deployed to the remote development environment and production environment. There are quite a lot of operation steps, and I found it based on the principle that the machine can do it and never do it manually. After comparing several automatic deployment schemes, we found that maven's cargo-maven2-plugin plugin is the most suitable for the current scenario. Let me share it.
The working principle of this plug-in is to use the manager application that comes with tomcat to deploy web applications. The project introduction https://codehaus-cargo.github.io/cargo/Home.html
The steps to be done are also quite simple. tomcat8 as an example. First make sure that the manager application already exists under tomcat in the remote environment to be deployed, then configure the role username and password accessed by the manager under tomcat8, modify the tomcat8/conf/tomcat-users.xml file, and add the following configuration:
- <role rolename="manager-gui"/>
- <role rolename="manager-script"/>
- <role rolename="manager-jmx"/>
- <role rolename="manager-status"/>
- <user username="admin" password="123456" roles="manager-gui,manager-script,manager-jmx,manager-status"/>
In order to allow users to access manager as text, it is best to configure all four tomcat predefined roles manager-gui, manager-script, manager-jmx, manager-status on the assigned username and
then in the actual web project Add the plugin configuration to the pom file:
- <plugin>
- <groupId>org.codehaus.cargo</groupId>
- <artifactId>cargo-maven2-plugin</artifactId>
- <version>1.5.0</version>
- <configuration>
- <container>
- <containerId>tomcat8x</containerId>
- <type>remote</type>
- </container>
- <configuration>
- <type>runtime</type>
- <properties>
- <cargo.protocol>http</cargo.protocol>
- < cargo.hostname > actual domain name </ cargo.hostname >
- < cargo.servlet.port > actual port number </ cargo.servlet.port >
- <cargo.remote.username>admin</cargo.remote.username>
- <cargo.remote.password>123456</cargo.remote.password>
- < cargo.remote.uri > http://actual domain name:actual port number/manager/text </ cargo.remote.uri >
- </properties>
- </configuration>
- </configuration>
- </plugin>
cargo.remote.username and cargo.remote.password are the username and password of the user node in the tomcat-users.xml file configured above, and http://actual domain name:actual port number/ in cargo.remote.uri is the remote deployment The root path address that tomcat actually accesses.
Finally, run the command in the web project root directory:
- mvn org.codehaus.cargo:cargo-maven2-plugin:redeploy
One-click remote deployment of web applications is done.
If you want the command to be shorter, you can add a pluginGroup to maven's settings.xml:
- <pluginGroups>
- <pluginGroup>org.codehaus.cargo</pluginGroup>
- </pluginGroups>
This command can be abbreviated as:
- mvn cargo:redeploy