使用wagon-maven-plugin外掛程式自動部署項目

來源:互聯網
上載者:User

該外掛程式的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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.