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

后端 未结 3 1759
春和景丽
春和景丽 2021-01-13 03:35

I am creating a dummy maven project with two modules, and I have included a general pom.xml file. I am able to build from the root pom.xml file and run all the tests but wh

相关标签:
3条回答
  • 2021-01-13 03:51

    Try using version 2.0-beta-1 of the plugin.
    See https://issues.apache.org/jira/browse/MTOMCAT-68

    0 讨论(0)
  • 2021-01-13 03:52
    <properties>
       <maven.tomcat.url>http://localhost:8080/manager/text</maven.tomcat.url>
    </properties>
    

    Fixed it for me.

    0 讨论(0)
  • 2021-01-13 04:00

    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.

    Step 1 : Find the url & role for tomcat to deploy war files.

    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"

       <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

    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.

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

    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.

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

    Now for the maven plugin to deploy the war file to tomcat , it needs the username & password for your tomcat server. Find out settings.xml of maven is located ( mine was at apache-maven-3.2.3\conf ) and apply the below config to the

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

    Step 5 : Moment of truth

    Start tomcat.

    mvn package ( war file created )

    mvn tomcat:deploy ( watch tomcat console for the war deployment )

    Your webapp will be available at http://localhost:8080/{context}

    0 讨论(0)
提交回复
热议问题