该插件的maven依赖为:
<dependency> <groupId>org.codehaus.mojo</groupId> <artifactId>wagon-maven-plugin</artifactId> <version>1.0</version> </dependency>
http://www.mojohaus.org/wagon-maven-plugin/
主要提供如下几个goal
用法如下:
为了让wagon-maven-plugin插件能SSH连上Linux服务器,首先需要在Maven的配置文件settings.xml中配置好server的用户名和密码。
<server> <id>webserver</id> <username>hadoop</username> <password>123</password> </server>
使用该插件,需要在build里面配置如下内容
<extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ssh</artifactId> <version>2.10</version> </extension> </extensions>
如下演示了一个,使用该查询部署一个war到tomcat的过程
<build> <finalName>osc-shop</finalName> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ssh</artifactId> <version>2.10</version> </extension> </extensions> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>wagon-maven-plugin</artifactId> <version>1.0</version> <configuration> <serverId>webserver</serverId> <!-- 需要部署的文件 --> <fromFile>target/osc-shop.war</fromFile> <!-- 部署目录 --> <url>scp://[email protected]/home/hadoop/apache-tomcat-8.0.5/webapps/ </url> <commands> <!-- 关闭tomcat --> <command>/home/hadoop/apache-tomcat-8.0.5/bin/shutdown.sh</command> <!-- 删除之前解压后的目录 --> <command>rm -rf /home/hadoop/apache-tomcat-8.0.5/webapps/osc-shop </command> <!-- 启动tomcat --> <command>/home/hadoop/apache-tomcat-8.0.5/bin/startup.sh</command> </commands> <displayCommandOutputs>true</displayCommandOutputs> </configuration> </plugin> </plugins> </build>
mvn clean package wagon:upload-single wagon:sshexec
即可部署到服务器,并且重启了tomcat