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

后端 未结 3 1760
春和景丽
春和景丽 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 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"

       
        
          Text Manager interface (for scripts)
          /text/*
        
        
           manager-script
        
      
    

    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.

    
    
      
      
      
      
      
    
    
    

    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.

        
                org.codehaus.mojo
                tomcat-maven-plugin
                
                    mytomcatserver
                    http://localhost:8080/manager/text
                
        
    

    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

    
      
          mytomcatserver
          admin
          admin
        
    
    

    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}

提交回复
热议问题