Maven 配置Tomcat

1.Tomcat conf 下的tomcat-users.xml 增加

<role rolename="manager"/>
<role rolename="admin"/>
<role rolename="manager-gui"/>
<user username = "admin" password = "password" roles = "admin,manager,manager-gui,manager-script,manager-jmx,manager-status" />

启动tomcat7,然后访问 http://localhost:8080/manager/html,输入admin/password,如果出现以下界面,表示tomcat一切OK

如果是Tomcat6 http://localhost:8080/manager

2.在Maven的conf目录中的setting.xml servers节点增加

<server>  
    <id>healthpad</id>  
    <username>admin</username>  
    <password>password</password>  
</server>

 

3.pom 配置

<build>
        <finalName>org.tinygroup.studytiny</finalName>
        <pluginManagement>
            <plugins>
                <!-- <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> 
                    <version>2.0-beta-1</version> </plugin> -->

                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1.1</version>
                    <configuration>
                        <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>tomcat-maven-plugin</artifactId>
                    <version>1.1</version>
                    <configuration>
                        <url>http://localhost:8080/manager/text</url>
                        <server>myserver</server>
                        <username>admin</username>
                        <password>admin</password>
                    </configuration>
                </plugin>                
            </plugins>
            <!-- 注释掉原来的调用Jetty的地方 -->
            <!-- <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> 
                <version>6.1.26</version> <dependencies> <dependency> <groupId>org.mortbay.jetty</groupId> 
                <artifactId>servlet-api-2.5</artifactId> <version>6.1.14</version> </dependency> 
                </dependencies> <configuration> <webApp>${basedir}/target/${project.artifactId}</webApp> 
                <contextPath>/${project.artifactId}</contextPath> <scanIntervalSeconds>10</scanIntervalSeconds> 
                <stopKey>foo</stopKey> <stopPort>9999</stopPort> </configuration> <executions> 
                <execution> <id>start-jetty</id> <phase>pre-integration-test</phase> <goals> 
                <goal>run</goal> </goals> <configuration> <scanIntervalSeconds>0</scanIntervalSeconds> 
                <daemon>true</daemon> </configuration> </execution> <execution> <id>stop-jetty</id> 
                <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> 
                </executions> </plugin> -->

        </pluginManagement>
    </build>
View Code

 

4.

Tomcat6 在Url中输入 http://localhost:8080/manager

右击Java项目,运行 输入 在Goals中添加:package tomcat:redeploy

 

5.异常解决

  • A.Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project healthpad:Cannot invoke Tomcat manager:Server returned HTTP response code:401for URL: http://localhost:8080/manager/html/deploy?path=%2FmkyWebApp&war= -> [Help 1]
    这种问题在 pom.xml中增加 username password

<configuration>
  <url>http://localhost:8080/manager/html</url>
  <server>healthpad</server>
  <username>admin</username> 
  <password>password</password> 
</configuration>

  •  B.

如果是403,请手工在浏览器中访问

http://localhost:8080/manager/html/deploy  调整 tomcat下的tomcat-users.xml 角色权限
  • C.
    Cannot invoke Tomcat manager: Error writing to server

我遇到过跟你一样的提示,myeclipse10+tomcat7+maven3,我的原因还是在pom文件上,使用tomcat6的时候,配置如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<server>tomcat</server>
<url>http://localhost/manager/html</url>
<path>/</path>
</configuration>
</plugin>
如果是tomcat7或者tomcat8的话,url必须改成这样
<url>http://localhost/manager/text</url>
才行
希望我的回答对你有帮助,我也是刚开始使用maven

  • 还有一个是拒绝连接,原因就是tomcat 没有启动

 

posted @ 2016-10-11 14:48  maanshancss  阅读(1791)  评论(1编辑  收藏  举报