如何利用maven插件部署項目到遠程運行環境

如何利用maven插件部署項目到遠程運行環境

你還在利用FTP的方式上傳你的War包嗎,這裏有一種更簡單好用的方式,那就是maven的cargo插件。


Cargo是一組幫助用戶操作Web容器的工具,它能幫助用戶實現自動化部署,而且它幾乎支持所有的Web容器,如Tomcat、JBoss、Jetty和Glassfish。Cargo通過cargo-maven2-plugin提供了Maven集成,Maven用戶可以使用該插件將Web項目部署到Web容器中。


Cargo支持兩種供本地部署方式,

  1. 一種遠程部署方式,本地部署分爲standalone模式和existing模式。
    在standalone模式中,Cargo會從Web容器的安裝目錄複製一份配置到用戶指定的目錄,並且部署應用。
  2. 在existing模式中,用戶需要指定現有的Web容器配置目錄,然後Cargo會直接使用這些配置並將應用部署到其對應的位置。

1、在maven中配置

<plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.7.1</version>
            <configuration>
                <container>
                    <!--Tomcat版本 7x 8x-->
                    <containerId>tomcat8x</containerId>
                    <type>remote</type><!--遠程部署-->
                </container>
                <configuration>
                    <type>runtime</type>
                    <properties>
                        <cargo.hostname>你服務器的IP</cargo.hostname><!--ip-->
                        <cargo.servlet.port>你服務器的端口</cargo.servlet.port><!--端口-->
                        <cargo.protocol>http</cargo.protocol><!--協議-->
                        <cargo.rmi.port>1099</cargo.rmi.port>
                        <cargo.remote.username>admin</cargo.remote.username><!--賬號密碼-->
                        <cargo.remote.password>lushuifa</cargo.remote.password><!--賬號密碼-->
                        <!--訪問路徑-->
                        <cargo.tomcat.manager.url>http://39.105.145.103:8080/</cargo.tomcat.manager.url>
                    </properties>
                </configuration>
            </configuration>
        </plugin>

2、在idea中如何使用見下圖

-w413

3、服務器tomcat對應配置

tomcat中主要配置一下用戶和密碼和角色,不情楚的可以百度一下。

<role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-jmx"/>
  <role rolename="manager-status"/>
  <user username="用戶名" password="密碼"  roles="manager-gui,manager-script,manager-jmx,manager-status" />
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章