gpt4 book ai didi

java - maven tomcat7部署报错403

转载 作者:行者123 更新时间:2023-11-28 22:13:04 25 4
gpt4 key购买 nike

你好

我知道这个问题已经在这里提出过好几次了,我读了很多答案,不幸的是,到目前为止,我什么都没用。

我在用什么:

  • Windows7
  • Tomcat 7
  • Maven - 插件“tomcat7-maven-plugin”
  • 应用程序在后端有java,前端有javascript

到目前为止的工作:我可以手动编译、构建、...、部署 war,并且 webapp 在本地主机上运行良好。

我现在尝试的是:

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

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

ma​​ven的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 中(以管理员权限打开)

mvn tomcat:部署

导致以下 403 错误消息:(本地主机需要被“删除”)

    [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

问题:

为什么会出现此错误?当然,我该如何修复它?

实际上我真的不能说得很准确,因为我想我检查了一切,甚至什么文件夹有什么权限。

希望得到意见和帮助。

提前致谢,梅鲁

最佳答案

我想将您的解决方案添加为“答案”,因为我搜索了很长时间,也许其他人那时不需要花那么多时间在上面。正如我已经写过的那样,需要将注释“文本”附加到 pom.xml 中插件的插件部分内的 url。让我分享一下我现在得到的:

ma​​ven>conf>settings.xml

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

tomcat>conf>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"/>

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

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

关于java - maven tomcat7部署报错403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23030279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com