2012-01-22 64 views
5

我正在用两个模块创建一个虚拟maven项目,并且包含了一个通用的pom.xml文件。我能够从根pom.xml文件构建并运行所有测试,但是当涉及到将文件部署到Tomcat时,它会崩溃。该插件我已经是:为什么tomcat-maven-plugin试图部署到错误的URL?

<build> 
    <finalName>dummy</finalName> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>tomcat-maven-plugin</artifactId> 
      <configuration> 
       <url>http://127.0.0.1:8090/manager/text</url> 
       <server>TomcatServer</server> 
       <path>/dummy</path> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

的settings.xml

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

然而,当我运行生成它使用默认配置值,我得到了以下错误消息:

未能执行目标org.codehaus.mojo:tomcat-maven-plugin:1.1:在项目上部署(default-cli)webapp:无法调用Tomcat管理器:http://localhost:8080/manager/deploy?path=%2Fwebapp&war= - > [Help 1]

有谁知道我可以如何让插件使用我的配置?

更多输出:

[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ webapp --- 
[INFO] Packaging webapp 
[INFO] Assembling webapp [webapp] in [C:\Websites\www.dummy.app\webapp\target\webapp] 
[INFO] Processing war project 
[INFO] Copying webapp resources [C:\Websites\www.dummy.app\webapp\src\main\webapp] 
[INFO] Webapp assembled in [15 msecs] 
[INFO] Building war: C:\Websites\www.dummy.app\webapp\target\webapp.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) @ webapp <<< 
[INFO] 
[INFO] --- tomcat-maven-plugin:1.1:deploy (default-cli) @ webapp --- 
[INFO] Deploying war to http://localhost:8080/webapp 
[INFO] ------------------------------------------------------------------------ 
[INFO] Reactor Summary: 
[INFO] 
[INFO] my-app ............................................ SUCCESS [4.747s] 
[INFO] webapp ............................................ FAILURE [3.313s] 
[INFO] dummy ............................................. SKIPPED 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 9.376s 
[INFO] Finished at: Mon Jan 23 22:46:11 GMT 2012 
[INFO] Final Memory: 18M/245M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project webapp: Cannot invoke Tomcat manager: http://localhost:8080/manager/deploy?path=%2Fwebapp&war= -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[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 
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command 
[ERROR] mvn <goals> -rf :webapp 

感谢

+1

您的经理URL看起来奇怪 - 为什么那里有一个'/ text'的名字?另外,您是否已验证Tomcat已正确配置为在端口8080上运行,并且该管理器应用程序已安装? – Perception

+1

要在Tomcat7上部署,URL需要以/ html或/ text结尾。我认为它应该是/文本,但我没有得到那么多的测试:)。 Tomcat运行在正确的端口上,因为http://127.0.0.1:8090/manager/html解析为Tomcat管理器 – BIGDeutsch

+1

您可以发布以调试模式运行它的相关控制台日志('mvn -X')吗? – Raghuram

回答

3
<properties> 
    <maven.tomcat.url>http://localhost:8080/manager/text</maven.tomcat.url> 
</properties> 

固定对我来说。

1

我也有同样的问题。以下是我的解决方法。虽然这是一个迟到的答案,但我认为这个答案即使在今天也是如此。

我使用tomcat7.The Tomcat的Maven的插件:1.1默认到tomcat部署URL http://localhost:8080/manager/html,但的Tomcat 7的网址已变为http://localhost:8080/manager/text

步骤1:找到tomcat部署war文件的url &角色。

我发现,通过手动将

apache-tomcat-7.0.41\webapps\manager\WEB-INF\web.xml 

用于部署的网址是:/文,所以行家应该使用http://localhost:8080/manager/text 这个网址的作用是“经理脚本

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Text Manager interface (for scripts)</web-resource-name> 
     <url-pattern>/text/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>manager-script</role-name> 
    </auth-constraint> 
    </security-constraint> 

步骤2:配置tomcat凭证角色

所以现在我们已经找到了部署war和角色的URL。如果你还没有配置tomcat users.Below是如何将角色添加到apache-tomcat-7.0.41 \ conf \的tomcat-users.xml中。

<tomcat-users> 

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

</tomcat-users> 

步骤3:在pom.xml中配置Tomcat,Maven的插件使用tomcat的URL进行部署。

现在我们需要配置tomcat-maven-plugin来使用这些。下面是我在pom.xml中的插件配置。这将覆盖tomcat-maven-plugin的默认tomcat部署url。

<plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>tomcat-maven-plugin</artifactId> 
      <configuration> 
       <server>mytomcatserver</server> 
       <url>http://localhost:8080/manager/text</url> 
      </configuration> 
    </plugin> 

步骤4:为tomcat url证书配置maven的settings.xml。

现在的Maven插件部署war文件到tomcat,它需要你的Tomcat服务器的用户名密码& 。 找出行家的settings.xml中的位置(我的是在Apache的行家-3.2.3 \ CONF)和下面的配置适用于

<servers> 
    <server> 
     <id>mytomcatserver</id> 
     <username>admin</username> 
     <password>admin</password> 
    </server> 
</servers> 

步骤5:人面桃花

启动tomcat。

MVN包(创建war文件)

MVN tomcat的:部署(看的战争部署tomcat的控制台)

你的web应用程序将可在http://localhost:8080/{context}

相关问题