maven tomcat7部署错误403

时间:2014-04-12 12:19:09

标签: java maven tomcat plugins deployment

你好

我知道这个问题已经在这里多次提出了,我读了许多答案,不幸的是,到目前为止没有任何效果。

我在用什么:

  • Windows7
  • Tomcat 7
  • Maven - 插件'tomcat7-maven-plugin'
  • 应用程序在后端使用java,前端是javascript

到目前为止工作的是什么: 我可以手动编译,构建,...,部署战争,并且webapp可以在localhost中正常运行。

我现在尝试的内容:

使用Maven构建并自动部署应用程序。 通过tomcat-plugin,我计划自动部署生成的war文件。我希望这个想法不是错的;如果是的话,请告诉我。

好的,让我列出我在不同文件中设置的内容以及我执行的内容。

maven的Settings.xml:

<server>
  <id>TomcatServer</id>
  <username>testuser</username>
  <password>testpw</password>
</server>

Tomcat的users.xml中:

我决定采取所有措施,这样就不会错过任何角色并导致问题。我也尝试过使用“manager-gui”和“manager-gui and admin”。

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

的pom.xml:

...
<modelVersion>4.0.0</modelVersion>
<groupId>com.mr</groupId>
<artifactId>myWebapp</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>my Web App</name>
<url>http://maven.apache.org</url>
<dependencies>

 ...
<plugins>
        <plugin>
             <groupId>org.apache.tomcat.maven</groupId>
             <artifactId>tomcat7-maven-plugin</artifactId>
             <version>2.0</version>
             <configuration>
                 <url>http://LuklHost:port/manager</url>
                 <server>TomcatServer</server>
                 <username>testuser</username>
                 <password>passwd</password>
                 <path>/myWebapp</path>
             </configuration>
         </plugin>
</plugins>

部署步骤:

在powershell中(使用admin-rights打开)

mvn tomcat:deploy

导致以下403错误消息: (localhost需要“删除”)

    [INFO] Deploying war to http://localhost:8080/TripleDictionary
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.821s
[INFO] Finished at: Sat Apr 12 13:59:37 CEST 2014
[INFO] Final Memory: 18M/223M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project TripleDictionary: Ca
nnot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/deploy?path=%2FTri
pleDictionary&war= -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:depl
oy (default-cli) on project TripleDictionary: Cannot invoke Tomcat manager
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
        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:317)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
        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:601)
        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)
Caused by: org.apache.maven.plugin.MojoExecutionException: Cannot invoke Tomcat manager
        at org.codehaus.mojo.tomcat.AbstractCatalinaMojo.execute(AbstractCatalinaMojo.java:149)
        at org.codehaus.mojo.tomcat.AbstractWarCatalinaMojo.execute(AbstractWarCatalinaMojo.java:70)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 19 more
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/deploy?path=%2
FTripleDictionary&war=
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1625)
        at org.codehaus.mojo.tomcat.TomcatManager.invoke(TomcatManager.java:604)
        at org.codehaus.mojo.tomcat.TomcatManager.deployImpl(TomcatManager.java:662)
        at org.codehaus.mojo.tomcat.TomcatManager.deploy(TomcatManager.java:295)
        at org.codehaus.mojo.tomcat.AbstractDeployWarMojo.deployWar(AbstractDeployWarMojo.java:85)
        at org.codehaus.mojo.tomcat.AbstractDeployMojo.invokeManager(AbstractDeployMojo.java:85)
        at org.codehaus.mojo.tomcat.AbstractCatalinaMojo.execute(AbstractCatalinaMojo.java:141)
        ... 22 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

问题:

为什么会出现此错误?当然,我该如何解决?

其实我真的不能说得准确,因为我觉得我检查了一切,甚至是哪个文件夹都有哪些权利。

希望有想法和帮助。

提前致谢, 梅鲁

1 个答案:

答案 0 :(得分:2)

我想把这个解决方案添加为“答案”,因为我搜索了它很长时间,也许其他人不需要花费那么多时间就可以了。正如我已经写过评论&#39; text&#39;需要附加到插件中的url - pom.xml中插件的一部分。 让我分享一下我现在得到的东西:

<强>行家&GT; CONF&GT; settings.xml中

<server>
   <id>TomcatServer</id>
   <username>testuser</username>
   <password>testpw</password>
</server>

<强>的Tomcat&GT; CONF&GT; Tomcat的users.xml中

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

但我认为最重要的是更改网址,这也是我问题的答案。

<强>的pom.xml:

<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>TomcatServer</server>
            <username>testuser</username>
            <password>passwd</password>
            <path>/myWebApp</path>
       </configuration>
   </plugin>
在PowerShell中

命令

  

mvn tomcat7:deploy