简体   繁体   English

为什么tomcat-maven-plugin尝试部署到错误的URL?

[英]Why is tomcat-maven-plugin trying to deploy to the wrong URL?

I am creating a dummy maven project with two modules, and I have included a general pom.xml file. 我正在创建一个带有两个模块的虚拟Maven项目,并且其中包括一个常规的pom.xml文件。 I am able to build from the root pom.xml file and run all the tests but when it comes to deploying the files to Tomcat, it falls down. 我能够从根pom.xml文件构建并运行所有测试,但是在将文件部署到Tomcat时却失败了。 The plugin I have is: 我的插件是:

<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 settings.xml

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

However, when I run the build it uses the default configuration values and I get the following error message: 但是,当我运行构建时,它使用默认配置值,并且收到以下错误消息:

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] 无法在项目Web应用程序上执行目标org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy(default-cli):无法调用Tomcat管理器: http:// localhost:8080 / manager / deploy?path =%2Fwebapp&war = -> [帮助1]

Does anyone know how I can get the plugin to be using my config? 有谁知道我如何才能使用我的配置插件?

More output: 更多输出:

[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

Thanks 谢谢

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

Fixed it for me. 为我修复它。

I also had the same problem.Here is how I resolved.Though this is a late answer,I think this answer will hold true even today. 我也有同样的问题。这是我的解决方法。虽然这是一个很晚的答案,但我认为这个答案在今天仍然适用。

I am using tomcat7.The tomcat-maven-plugin:1.1 defaults to tomcat deployment url http://localhost:8080/manager/html , but for tomcat 7 the url has changed to http://localhost:8080/manager/text . 我正在使用tomcat7。tomcat-maven-plugin:1.1默认为tomcat部署URL http://localhost:8080/manager/html ,但是对于tomcat 7 ,URL已更改为http://localhost:8080/manager/text

Step 1 : Find the url & role for tomcat to deploy war files. 步骤1:找到Tomcat的URL和角色,以部署War文件。

I found that by manually going to 我发现通过手动转到

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

The url used to deploy is : /text , so maven should use http://localhost:8080/manager/text The role for this url is " manager-script " 用于部署的URL是: / text ,因此maven应该使用http://localhost:8080/manager/text该URL的角色是“ manager-script

   <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>

Step 2 : Configure tomcat credentials for the role 步骤2:为角色配置tomcat凭据

So now we have found the URL to deploy the war and the role.If you havent configured tomcat users.Below is how to add the roles to apache-tomcat-7.0.41\\conf\\tomcat-users.xml. 所以现在我们找到了部署战争和角色的URL。如果您尚未配置tomcat用户。下面是如何将角色添加到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>

Step 3: Configure tomcat-maven-plugin in pom.xml to use the tomcat url for deployment. 步骤3:在pom.xml中配置tomcat-maven-plugin以使用tomcat url进行部署。

Now we need to configure tomcat-maven-plugin to use these.Below is my plugin configuration in the pom.xml.This will override the tomcat-maven-plugin's default tomcat deploy 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>

Step 4 : Configure maven's settings.xml for the tomcat url credentials. 步骤4:为tomcat url凭证配置maven的settings.xml。

Now for the maven plugin to deploy the war file to tomcat , it needs the username & password for your tomcat server. 现在,要让maven插件将war文件部署到tomcat,它需要您的tomcat服务器的用户名和密码。 Find out settings.xml of maven is located ( mine was at apache-maven-3.2.3\\conf ) and apply the below config to the 找出maven的settings.xml文件(我的文件位于apache-maven-3.2.3 \\ conf)并将以下配置应用于

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

Step 5 : Moment of truth 步骤5:关键时刻

Start tomcat. 启动tomcat。

mvn package ( war file created ) mvn包(创建war文件)

mvn tomcat:deploy ( watch tomcat console for the war deployment ) mvn tomcat:deploy(观看用于战争部署的tomcat控制台)

Your webapp will be available at http://localhost:8080/{context} 您的Web应用将可通过http://localhost:8080/{context}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM