如何通過Maven的Tomcat外掛程式運行Web工程

來源:互聯網
上載者:User

標籤:配置   sap   mave   color   XML   run   tin   maven   相關   

去tomcat官網http://tomcat.apache.org/,左側欄Apache Tomcat下的Maven Plugin,點進去選擇最新版本Version 2.2

通過介紹可知,使用tomcat的maven外掛程式有兩種配置方式:

第一種:在pom.xml檔案的<build></build>中加入如下配置:

 1 <pluginManagement>   2     <plugins>   3         <plugin>   4             <groupId>org.apache.tomcat.maven</groupId>   5             <artifactId>tomcat6-maven-plugin</artifactId>   6             <version>2.2</version>   7         </plugin>   8         <plugin>   9             <groupId>org.apache.tomcat.maven</groupId>  10             <artifactId>tomcat7-maven-plugin</artifactId>  11             <version>2.2</version>  12         </plugin>  13     </plugins>  14 </pluginManagement>  

這種配置是針對某一個項目的,只對一個項目生效。

 

第二種:在maven的setting.xml檔案中加入如下配置:

1 <pluginGroups>  2     <pluginGroup>org.apache.tomcat.maven</pluginGroup>  3 </pluginGroups>  

這種在maven外掛程式上的配置會對所有的項目起作用。

 

配置好之後,就可以啟動項目看效果了。

使用Maven Build啟動項目,Goals那一欄填:

tomcat6:run -Dmaven.tomcat.uriEncoding=UTF-8 -Dmaven.tomcat.path=/ -Dmaven.tomcat.port=8080

或者填:

tomcat7:run -Dmaven.tomcat.uriEncoding=UTF-8 -Dmaven.tomcat.path=/ -Dmaven.tomcat.port=8080

其中,

-Dmaven.tomcat.uriEncoding=UTF-8 這個配置最好始終加上

-Dmaven.tomcat.path=/ 這個配置可以不加,預設使用/${artifactId},此處的artifactId即建pom.xml檔案時寫的那個artifactId,一般為項目名。如果配置為/的話,屆時訪問的路徑就是hostname:port/,如果配置為/test的話,則訪問路徑是hostname:port/test,相當於namesapce的作用。

-Dmaven.tomcat.port=8080 這個配置可以設定,預設是8080

以上兩種啟動方式的區別僅在於使用的tomcat的版本不一樣。如果使用tomcat7的話,則如果配置方式是在pom.xml檔案中配置的話,則必須配置tomcat7-maven-plugin,否則會BUILD FAILURE;如果配置方式是配置maven的setting.xml檔案的話,則無所謂,<pluginGroup>org.apache.tomcat.maven</pluginGroup>這一行的作用是把所有版本的maven的tomcat外掛程式及相關外掛程式都下載下來了。使用tomcat6的話也同理。

如何通過Maven的Tomcat外掛程式運行Web工程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.