Maven 整合Tomcat或tomcat7外掛程式

來源:互聯網
上載者:User

Maven已經是Java的專案管理標配,如何在JavaEE開發使用Maven調用Web應用,是很多同學關心的問題。本文將介紹,Maven如何介紹Tomcat外掛程式。

Maven Tomcat外掛程式現在主要有兩個版本,tomcat-maven-plugin和tomcat7-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。

 tomcat-maven-plugin  外掛程式使用 配置

在pom.xm 加入以下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  URL按UTF-8進行編碼,這樣就解決了中文參數亂碼。

Server 指定tomcat名稱。

配置就這麼簡單,基本搞掂,下面看看如何使用。 外掛程式運行

如果Eclipse 安裝了Maven外掛程式,選 擇pom.xml檔案,擊右鍵——>選擇 Run As——> Maven build 。


 

如果是第一次運行,會彈出下面對話方塊。在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 ,並運行當前項目
tomcat7-maven-plugin 使用 配置

兩個外掛程式使用方法基本一樣,同樣需要在pom.xml引用該外掛程式,需要增加以下配置

 

            <plugin>                <groupId>org.apache.tomcat.maven</groupId>                <artifactId>tomcat7-maven-plugin</artifactId>                <version>2.1</version>                <configuration>                    <port>9090</port>                    <path>/mgr</path>                    <uriEncoding>UTF-8</uriEncoding>                    <finalName>mgr</finalName>                    <server>tomcat7</server>                </configuration>            </plugin>

具體配置一樣。 外掛程式使用 

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

 

 

OK,配置就這麼簡單,如果需要在 tomcat 跟蹤聯調,可以用Dubug 方式啟動maven命令。

聯繫我們

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