該外掛程式的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:upload-single uploads the specified file to a remote location.
wagon:upload uploads the specified set of files to a remote location.
wagon:download-single downloads the specified file from a remote location.
wagon:download downloads the specified set of files from a remote location.
wagon:list lists the content of a specified location in a remote repository.
wagon:copy copies a set of files under a Wagon repository to another.
wagon:merge-maven-repos merges , including metadata, a Maven repository to another.
wagon:sshexec Executes a set of commands at remote SSH host.
用法如下:
為了讓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://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>
配置完成後,執行命令
mvn clean package wagon:upload-single wagon:sshexec
即可部署到伺服器,並且重啟了tomcat