Maven在尝试部署tomcat时出错

时间:2015-03-02 14:58:25

标签: eclipse maven tomcat7

我已经在stackoverflow上阅读了与此相关的答案,但我仍然遇到了这个问题。

我的tomcat-users.xml:

    <role rolename = "manager-gui" /> 
    <role rolename = "manager-script" /> 
    <user username = "AppManager"password ="password"roles ="manager-gui"/> 
    <user username = "tomcatmvn" password = "password" roles = "manager-script" /> 

的pom.xml:

           <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <url>http://localhost:8080/manager/text</url>
                    <server>TomcatServer</server>
                    <path>/myproject</path>
                </configuration>
            </plugin>

的settings.xml

    <server> 
       <id>TomcatServer</id> 
       <username>tomcatmvn</username> 
       <password>password</password> 
    </server> 

当我使用以下内容时:mvn -X tomcat7:deploy 我收到以下错误:

Tomcat return http status error: 403, Reason Phrase: Forbidden: <html><head><title>Apache Tomcat/7.0.47 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 403 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>Access to the specified resource has been forbidden.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.47</h3></body></html>
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

引起:org.apache.maven.plugin.MojoExecutionException:Tomcat返回http状态错误:403,Reason Phrase:Forbidden:Apache Tomcat / 7.0.47 - 错误报告

HTTP状态403 - < / h1>

类型状态报告

消息

描述访问指定的资源已被禁止。

Apache Tomcat / 7.0.47

    at org.apache.tomcat.maven.plugin.tomcat7.AbstractTomcat7Mojo.checkTomcatResponse(AbstractTomcat7Mojo.java:76)     at org.apache.tomcat.maven.plugin.tomcat7.deploy.AbstractDeployWarMojo.deployWar(AbstractDeployWarMojo.java:88)     在org.apache.tomcat.maven.plugin.tomcat7.deploy.AbstractDeployMojo.invokeManager(AbstractDeployMojo.java:82)     在org.apache.tomcat.maven.plugin.tomcat7.AbstractCatalinaMojo.execute(AbstractCatalinaMojo.java:132)     在org.apache.tomcat.maven.plugin.tomcat7.AbstractWarCatalinaMojo.execute(AbstractWarCatalinaMojo.java:68)     在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)     在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)     ......还有19个

enter code here

3 个答案:

答案 0 :(得分:0)

尝试这样的事情:

文件 pom.xml

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
      <url>http://localhost:8080/manager/text</url>
      <server>localhost</server>
      <path>/${project.build.finalName}</path>
    </configuration>
</plugin>


文件 ~/.m2/settings.xml

<servers>
     <server>
         <id>localhost</id>
         <username>tomcatmvn</username>
         <password>password</password>
     </server>
</servers>


文件 tomcat-users.xml

<role rolename="manager-script"/>
<user username="tomcatmvn" password="password" roles="manager-script"/>

更改tomcat-users.xml后重启服务器。您不应将manager-gui角色与manager-script分配给同一用户。

阅读更多:Apache Tomcat Maven Plugin官方文件和tutorial

答案 1 :(得分:0)

尝试删除当前的tomcat服务器文件夹并创建新文件夹。它适用于我:D

答案 2 :(得分:0)

应添加admin-gui并尝试使用管理员权限启动cmd