maven集成tomcat插件以及亂碼解決


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。

 

tomcat7-maven-plugin 插件使用

配置

在pom.xm 加入以下xml。

<plugin>
        groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <version>1.1</version>
               <configuration>
<!--path  是訪問應用的路徑--> <path>/wp</path>
<!--port 是tomcat 的端口號c--> <port>8080</port>
<!--uriEncoding  URL按UTF-8進行編碼,這樣就解決了中文參數亂碼--> <uriEncoding>UTF-8</uriEncoding> <url>http://localhost:8080/manager/html</url>
<!--Server 指定tomcat名稱。-->
<server>tomcat7</server>
</configuration>
</plugin>
 
        

  

插件運行


如果Eclipse 安裝了Maven插件,選 擇pom.xml文件,擊右鍵——>選擇 Run As——> Maven build -->輸入 tomcat7:run -->單擊run運行。

 這樣tomcat7就可以正常運行了。

 

下面介紹幾個常用的Goal

命令 描述
tomcat:deploy 部署一個web war包
tomcat:reload 重新加載web war包

tomcat:start

啟動tomcat

tomcat:stop

停止tomcat

tomcat:undeploy

停止一個war包
tomcat:run 啟動嵌入式tomcat ,並運行當前項目

   

tomcat-maven-plugin 插件使用與tomcat7-maven-plugin 插件使用一致,只要把<server>tomcat7</server>改為<server>tomcat7</server>即可

 
       


免責聲明!

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



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