使用 Tomcat 通过 Maven 部署 Eclipse WebApp 导致错误:“无法在上下文路径部署应用程序”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6329017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse WebApp deploying over Maven with Tomcat results in Error: 'Failed to deploy application at context path'
提问by Dominik
When I try deploying my HelloWorldproject as describet at IBM Developerworksto Tomcat 7 with Maven 3 using the command mvn tomcat:deploy
I get the error Failed to deploy application at context path /server
.
当我尝试使用命令将IBM Developerworks 中描述的HelloWorld项目部署到带有 Maven 3 的 Tomcat 7 时,出现错误。mvn tomcat:deploy
Failed to deploy application at context path /server
In the listed applications my /server appears but it can't be started.
在列出的应用程序中,我的 /server 出现但无法启动。
I modified my maven web project according to the tutorial at base22and applied the fix <url>http://localhost:8080/manager/html</url>
for Tomcat 7 deployment in the pom.xml as descibet at loquatic.
我根据base22上的教程修改了我的 maven web 项目,并<url>http://localhost:8080/manager/html</url>
在 pom.xml 中应用了Tomcat 7 部署的修复程序作为 loquatic 的描述。
The command:
命令:
mvn tomcat:deploy
The error:
错误:
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project server: Cannot
invoke Tomcat manager: FAIL - Failed to deploy application at context path /server -> [Help 1]
Tomcat tomcat-users.xml
Tomcat tomcat-users.xml
<tomcat-users>
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<role rolename="manager"/>
<role rolename="admin"/>
<user username="admin" password="admin" roles="admin,manager,admin-gui,manager-gui"/>
</tomcat-users>
Project web.xml
项目 web.xml
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>sample.hello.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
The error with -e:
-e 的错误:
PS C:\Users\Dom\work\server> mvn tomcat:deploy -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.elexess:server:war:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.codehaus.mojo:tomcat-maven-plugin is missing. @ line 58, column 18
[WARNING] 'repositories.repository.layout' for maven-repository.java.net uses the unsupported value 'legacy', artifact r
esolution might fail. @ line 52, column 14
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building server Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> tomcat-maven-plugin:1.1:deploy (default-cli) @ server >>>
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ server ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ server ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ server ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Dom\work\server\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ server ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ server ---
[INFO] Surefire report directory: C:\Users\Dom\work\server\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ server ---
[INFO] Packaging webapp
[INFO] Assembling webapp [server] in [C:\Users\Dom\work\server\target\server]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\Dom\work\server\src\main\webapp]
[INFO] Webapp assembled in [85 msecs]
[INFO] Building war: C:\Users\Dom\work\server\target\server.war
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')
[INFO]
[INFO] <<< tomcat-maven-plugin:1.1:deploy (default-cli) @ server <<<
[INFO]
[INFO] --- tomcat-maven-plugin:1.1:deploy (default-cli) @ server ---
[INFO] Deploying war to http://localhost:8080/server
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.017s
[INFO] Finished at: Tue Jun 14 08:00:14 CEST 2011
[INFO] Final Memory: 8M/164M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project server: Cannot
invoke Tomcat manager: FAIL - Failed to deploy application at context path /server -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1
:deploy (default-cli) on project server: Cannot invoke Tomcat manager: FAIL - Failed to deploy application at context pa
th /server
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:319)
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:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Cannot invoke Tomcat manager: FAIL - Failed to deploy applica
tion at context path /server
at org.codehaus.mojo.tomcat.AbstractCatalinaMojo.execute(AbstractCatalinaMojo.java:145)
at org.codehaus.mojo.tomcat.AbstractWarCatalinaMojo.execute(AbstractWarCatalinaMojo.java:70)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 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
Project pom.xml
项目 pom.xml
<build>
<finalName>server</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager/html</url>
<server>mytomcat</server>
<path>/${project.build.finalName}</path>
</configuration>
</plugin>
</plugins>
</build>
Maven settings.xml
Maven 设置.xml
<server>
<id>mytomcat</id>
<username>admin</username>
<password>admin</password>
</server>
回答by jasop
For Tomcat 7 you need to deploy with the "text" URL. This URL is what is used by scripts to deploy. You are trying to deploy with the "gui" URL.
对于 Tomcat 7,您需要使用“文本”URL 进行部署。此 URL 是脚本用于部署的 URL。您正在尝试使用“gui” URL 进行部署。
Here's how to set it up:
设置方法如下:
tomcat-users.xml
tomcat-users.xml
<role rolename="manager-script"/>
<user password="script" roles="manager-script" username="script"/>
Then, in your pom.xml you set the URL to be: "http://localhost:8080/manager/text/"
然后,在 pom.xml 中将 URL 设置为:“http://localhost:8080/manager/text/”
Also, in your maven settings.xml, set your username/password to be script/script.
此外,在您的 maven settings.xml 中,将您的用户名/密码设置为脚本/脚本。
回答by Ronald Randon
I get this error,
我收到这个错误,
Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project projectname:
Cannot invoke Tomcat manager: FAIL - Application already exists at path /path
Then I replaced the configuration from mvn tomcat:deploy
to mvn tomcat:redeploy
然后我将配置从mvn tomcat:deploy
到mvn tomcat:redeploy
回答by Tnem
The application already exists at that location, you need to undeploy it first.
该应用程序已存在于该位置,您需要先取消部署它。
You can either undeploy it first using the tomcat manager or through maven using
您可以先使用 tomcat 管理器或通过 maven 取消部署它
mvn tomcat:undeploy
or use the following command:
或使用以下命令:
mvn package tomcat:redeploy
to write over the current instance.
覆盖当前实例。
For more info look here
欲了解更多信息,请看这里
回答by cuh
The tomcat maven plugin usagepage says that
tomcat maven 插件使用页面说
The default Tomcat manager URL is http://localhost:8080/manager.
默认的 Tomcat 管理器 URL 是http://localhost:8080/manager。
I think you have to remove the /html
part from your configuration.
我认为您必须/html
从配置中删除该部分。