原文地址;http://my.oschina.net/lilw/blog/168667
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命令。如下圖
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
