該插件的maven依賴爲:web
<dependency> <groupId>org.codehaus.mojo</groupId> <artifactId>wagon-maven-plugin</artifactId> <version>1.0</version> </dependency>
用法以下:apache
爲了讓wagon-maven-plugin插件能SSH連上Linux服務器,首先須要在Maven的配置文件settings.xml中配置好server的用戶名和密碼。tomcat
<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的過程app
<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://hadoop@192.168.1.222/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>
配置完成後,執行命令ssh
mvn clean package wagon:upload-single wagon:sshexecwebapp
便可部署到服務器,而且重啓了tomcatmaven