maven自動部署項目以及常見問題解決

Maven自動部署war到Tomcat
1. 在maven項目的pom裏配置以下信息html

<build>
<finalName>dianxiao</finalName>	<!-- WAR包的名字 -->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<url>http://localhost:8080/manager/text</url>	<!-- tomcat的部署路徑,tomcat6的路徑爲http://localhost:8080/manager,tomcat7的配置路徑爲http://localhost:8080/manager/text -->
<username>admin</username>
<password>admin</password>
<path>/dianxiao</path>
</configuration>
<executions>
<execution>
<id>tomcat-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

  

2. 在Tomcat的tomcat-users.xml裏添加下面的信息
<rolerolename="manager"/>
<userusername="admin" password="admin"roles="manager"/>
3. 啓動Tomcat

4. 運行Maven build...
在Goals中填入package tomcat:redploy,點擊運行
5.查看Tomcat的webapps下面的文件,看是否多了兩個文件,其中有war包,若出現則成功!反之開始查找錯誤,參考如下內容web

 

在Maven與Tomcat配合部署過程當中,最多見的錯誤有三種,折騰了半天,終於找到三種錯誤產生的緣由,以及相應的完美解決辦法shell

1.Connection refused錯誤apache

報錯信息以下tomcat

[ERROR]Failed to execute goal org.apache.tomcat.maven: tomcat7-maven-plugin: 2.0- SNAPSHOT: deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Connection refused: connect -> [Help 1]

緣由:未啓動Tomcat服務器服務器

解決辦法:先啓動Tomcat服務器再選擇Runapp

2. 401錯誤webapp

報錯信息以下:maven

[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin: 2.0-SNAPSHOT:deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/text/deploy?path=%2Fhelloworld -> [Help 1]

緣由:權限問題ui

解決辦法在$CATALINA_BASE/conf/tomcat-users.xml,

如D:\apache-tomcat-7.0.34\conf\tomcat-users.xml文件中添加權限

<role rolename=」manager」/>
<user username=」admin」 password=」admin」 roles=」manager」/>

修改pom.xml文件,在<configuration>  

</configuration>中添加

<username>admin</username>  
<password>admin</password> 

3.403錯誤

報錯信息以下:

[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin: 2.0-SNAPSHOT:deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/html/deploy?path=%2Fhelloworld -> [Help 1]

 緣由:產生該問題有可能由於兩個緣由,具體參看法決辦法

解決辦法:

1)若是使用的是Tomcat 7,須要修改pom.xml中部署的url地址,將

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

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

在此次部署的問題上,我就是遇到了url 的問題,我用的是tomcat7

2)給tomcat用戶權限分配上,須要同時具有manager-gui和manager-script權限

正確的conf/tomcat-users.xml配置應爲:

<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin」 password="admin" roles="manager-gui, manager-script"/>
</tomcat-users>

參考文章:http://my.oschina.net/jerryhu/blog/295279

相關文章
相關標籤/搜索