Maven -Maven配置tomcat插件 兩種


Maven Tomcat插件現在主要有兩個版本,tomcat-maven-plugintomcat7-maven-plugin,使用方式基本相同。

tomcat-maven-plugin 插件官網:

http://mojo.codehaus.org/tomcat-maven-plugin/plugin-info.html

tomcat7-maven-plugin 插件官網:

http://tomcat.apache.org/maven-plugin.html

---------------------------------------------------------------------------------------------------

 

1tomcat-maven-plugin 插件使用

 

pom.xml中加入下面代碼:

   <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <path>/wp</path>
                    <port>8080</port>
                    <uriEncoding>UTF-8</uriEncoding>
                    <url>http://localhost:8080/manager/html</url>
                    <server>tomcat6</server>
                </configuration>
            </plugin>

簡要說明一下:

 

path  是訪問應用的路徑

 

port tomcat 的端口號

 

uriEncoding  URLUTF-8進行編碼,這樣就解決了中文參數亂碼。

 

 

 

Server 指定tomcat名稱。

 

如果Eclipse 安裝了Maven插件,選 擇pom.xml文件,擊右鍵——>選擇 Run As——> Maven build 。(如果為安裝插件,請查看博文eclipse安裝maven插件

 

如果是第一次運行,會彈出下面對話框。在Goals框加加入以下命令: tomcat:run

 

這樣Tomcat 插件就可以運行。

下面介紹幾個常用的Goal

 

tomcat:deploy   --部署一個web war包
tomcat:reload   --重新加載web war包
tomcat:start    --啟動tomcat
tomcat:stop    --停止tomcat
tomcat:undeploy--停止一個war包
tomcat:run  啟動嵌入式tomcat ,並運行當前項目

 

2tomcat7-maven-plugin 插件使用

 

 

在pom.xml中加入下面代碼:
<plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
               <configuration>
                  <path>/</path>
                  <port>8080</port>
                  <server>tomcat7</server>
               </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
        </plugin>

 

在這里要注意一下,該插件命名方式有些不同,比如啟動tomcat ,對應的目標命令是: tomcat7:run ,同樣,其它命令也是這樣,需要更改為:tomcat7<插件執行點>

 

 

tomcat7:deploy  --部署一個web war包
tomcat7:reload  --重新加載web war包
tomcat7:start    --啟動tomcat
tomcat7:stop    --停止tomcat
tomcat7:undeploy--停止一個war包
tomcat7:run 啟動嵌入式tomcat ,並運行當前項目
如果需要debug,就使用debug as 方式啟動項目!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM