Using the wagon Maven plugin plug-in to automatically deploy a project

The maven dependency of this plug-in is:

  1. <dependency>  
  2.     <groupId>org.codehaus.mojo</groupId>  
  3.     <artifactId>wagon-maven-plugin</artifactId>  
  4.     <version>1.0</version>  
  5. </dependency>  

The document address of the plug-in is:

http://www.mojohaus.org/wagon-maven-plugin/


It mainly provides the following goal s


The usage is as follows:


In order for the wagon Maven plugin to SSH to the Linux server, you need to configure the server user name and password in Maven's configuration file settings.xml.

  1. <server>  
  2.     <id>webserver</id>  
  3.     <username>hadoop</username>  
  4.     <password>123</password>  
  5. </server>  


To use this plug-in, you need to configure the following in build

  1. <extensions>  
  2.     <extension>  
  3.         <groupId>org.apache.maven.wagon</groupId>  
  4.         <artifactId>wagon-ssh</artifactId>  
  5.         <version>2.10</version>  
  6.     </extension>  
  7. </extensions>  


The following is a demonstration of how to deploy a war to tomcat using this query

  1. <build>  
  2.     <finalName>osc-shop</finalName>  
  3.     <extensions>  
  4.         <extension>  
  5.             <groupId>org.apache.maven.wagon</groupId>  
  6.             <artifactId>wagon-ssh</artifactId>  
  7.             <version>2.10</version>  
  8.         </extension>  
  9.     </extensions>  
  10.     <plugins>  
  11.         <plugin>  
  12.             <groupId>org.codehaus.mojo</groupId>  
  13.             <artifactId>wagon-maven-plugin</artifactId>  
  14.             <version>1.0</version>  
  15.             <configuration>  
  16.                 <serverId>webserver</serverId>  
  17.                 <!-- Files to deploy -->  
  18.                 <fromFile>target/osc-shop.war</fromFile>  
  19.                 <!-- Deployment directory -->  
  20.                 <url>scp://hadoop@192.168.1.222/home/hadoop/apache-tomcat-8.0.5/webapps/  
  21.                 </url>  
  22.                 <commands>  
  23.                     <!-- Close tomcat -->  
  24.                     <command>/home/hadoop/apache-tomcat-8.0.5/bin/shutdown.sh</command>  
  25.                     <!-- Delete the previously unzipped directory -->  
  26.                     <command>rm -rf /home/hadoop/apache-tomcat-8.0.5/webapps/osc-shop  
  27.                     </command>  
  28.                     <!-- start-up tomcat -->  
  29.                     <command>/home/hadoop/apache-tomcat-8.0.5/bin/startup.sh</command>  
  30.                 </commands>  
  31.                 <displayCommandOutputs>true</displayCommandOutputs>  
  32.             </configuration>  
  33.         </plugin>  
  34.     </plugins>  
  35. </build>  

When the configuration is complete, execute the command

mvn clean package wagon:upload-single wagon:sshexec

You can deploy to the server and restart tomcat


Tags: Maven Tomcat Hadoop Apache

Posted on Sun, 03 May 2020 15:55:34 -0700 by Sanoz0r