maven項目能夠自動發佈到tomcat下

屢次驗證,得把<</span>url>http://localhost:8080/manager/html</</span>url>調整爲http://localhost:8080/manager/text。html



多方搜索,終於使maven項目能夠自動發佈到tomcat下了。web

tomcat7 須要使用 tomcat-maven-plugin 的新版本,版本支持tomcat6和tomcat7,groupId也由org.codehaus.mojo改成org.apache.tomcat.maven。  能夠參考看看:http://tomcat.apache.org/maven-plugin.htmlapache

主菜來了。tomcat

1.修改項目的pom.xml  eclipse

a.在project節點下 添加tomcat-maven-plugin插件信息,以下寫法添加了tomcat6和tomcat7的插件,如只用1種能夠只寫一個maven

[html] view plaincopyui

  1. <</span>pluginManagement>  url

  2.     <</span>plugins>  spa

  3.         <</span>plugin>  .net

  4.             <</span>groupId>org.apache.tomcat.maven</</span>groupId>  

  5.             <</span>artifactId>tomcat6-maven-plugin</</span>artifactId>  

  6.             <</span>version>2.0</</span>version>       

  7.             <</span>configuration>  

  8.               <</span>url>http://localhost:8080/manager/html</</span>url>   

  9.               <</span>server>tomcat</</span>server>  

  10.             </</span>configuration>         

  11.         </</span>plugin>  

  12.         <</span>plugin>  

  13.             <</span>groupId>org.apache.tomcat.maven</</span>groupId>  

  14.             <</span>artifactId>tomcat7-maven-plugin</</span>artifactId>  

  15.             <</span>version>2.0</</span>version>  

  16.             <</span>configuration>  

  17.                 <</span>url>http://localhost:8080/manager/html</</span>url>   

  18.                 <</span>server>tomcat</</span>server>  

  19.             </</span>configuration>  

  20.         </</span>plugin>  

  21.     </</span>plugins>  

  22. </</span>pluginManagement>  

 

<plugin>

     <groupId>org.apache.tomcat.maven</groupId>

     <artifactId>tomcat7-maven-plugin</artifactId>

     <version>2.0</version>

     <configuration>

      <url>http://localhost:8080/manager/text</url>

      <server>tomcat</server>

      <username>admin</username>  

    <password>1234</password>  

    </configuration>

    </plugin>

--html能夠替換成text,此處必須替換爲text,不然報403。

 

b.在project節點下,添加倉庫信息,保證maven能夠從倉庫中下載到tomcat-maven-plugin插件,少添加了這段信息,沒有下載到插件,致使報錯,浪費了很多時間。

網上的帖子說要添加以下兩段信息,我的懷疑只須要添加1段。

 

[html] view plaincopy

  1. <</span>repository>  

  2.     <</span>id>people.apache.snapshots</</span>id>  

  3.     <</span>url>  

  4.         http://repository.apache.org/content/groups/snapshots-group/  

  5.     </</span>url>  

  6.     <</span>releases>  

  7.         <</span>enabled>false</</span>enabled>  

  8.     </</span>releases>  

  9.     <</span>snapshots>  

  10.         <</span>enabled>true</</span>enabled>  

  11.     </</span>snapshots>  

  12. </</span>repository>  


[html] view plaincopy

  1. <</span>pluginRepository>  

  2.     <</span>id>apache.snapshots</</span>id>  

  3.     <</span>name>Apache Snapshots</</span>name>  

  4.     <</span>url>  

  5.         http://repository.apache.org/content/groups/snapshots-group/  

  6.     </</span>url>  

  7.     <</span>releases>  

  8.         <</span>enabled>false</</span>enabled>  

  9.     </</span>releases>  

  10.     <</span>snapshots>  

  11.         <</span>enabled>true</</span>enabled>  

  12.     </</span>snapshots>  

  13. </</span>pluginRepository>  


 2.配置setting.xml,%MAVEN_HOME%\conf\setting.xml(前提是在myeclipse preferences中maven啓用本地安裝版本並設置用戶setting.xml爲本地conf下的setting.xml,而不是插件,插件應該是「個人文檔」\.m2\setting.xml),

在標籤中加入

[html] view plaincopy

  1. <</span>server>  

  2.        <</span>id>tomcat</</span>id>  

  3.        <</span>username>admin</</span>username>  

  4.        <</span>password>admin</</span>password>  

  5. </</span>server>  

id與pom.xml文件配置相同,用戶名密碼與tomcat_user相同。

本部分配置也可寫在pox.xml 的中

 

3.給tomcat配置用戶,%TOMCAT_HOME%\conf\tomcat_user.xml 增長如下角色和用戶,用於tomcat_maven_plugin自動部署工程

[html] view plaincopy

  1. <</span>role rolename="manager-gui"/>    

  2. <</span>role rolename="manager-script"/>    

  3. <</span>user username="admin" password="admin" roles="manager-gui, manager-script"/>    

4. 啓動tomcat,在工程或pom.xml上右鍵,maven build的goals中輸入命令tomcat7:deploy便可發佈,或在Run Configurations->Maven build新建一個命令,base directory裏選擇你的web project,在Goals欄可填寫你所須要的命令。

goals中使用的命令能夠參考http://tomcat.apache.org/maven-plugin-2.0-SNAPSHOT/tomcat7-maven-plugin/plugin-info.html 


參考連接:

http://hi.baidu.com/xikan/blog/item/66547fedb13201f5b21cb120.html

http://vivus.iteye.com/blog/1561664

相關文章
相關標籤/搜索