4

I am having trouble in deploying to remote machine with tomcat installed as aservice. My tomcat-users is as follows:

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

</tomcat-users>

My settings.xml is:

<settings>
<pluginGroups>
<pluginGroup>org.apache.tomcat.maven</pluginGroup>
</pluginGroups>
<servers>
<server>
  <id>tomcat7</id>
  <username>admin</username>
  <password>admin</password>
</server>

</servers>

</settings>

And my pom.xml has the following:

            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <server>tomcat7</server>
                    <url>http://localhost:8081/manager/text</url>
                    <warFile>target/editor-${project.version}.war</warFile>
                </configuration>

And I keep on getting the 401 Unauthorized on the output of maven console. Can you tell me what am I doing wrong?

Matthew
  • 9,851
  • 4
  • 46
  • 77
Arek
  • 1,941
  • 4
  • 22
  • 27
  • http://stackoverflow.com/questions/3714080/tomcat-7-maven-plugin – Paulius Matulionis Nov 06 '12 at 12:45
  • You can see my answer in http://stackoverflow.com/questions/16230666/failed-to-execute-goal-org-codehaus-mojotomcat-maven-plugin1-1deploy-default/16292897#16292897 – sancho21 Apr 30 '13 at 05:41
  • See my answer on http://stackoverflow.com/questions/16230666/failed-to-execute-goal-org-codehaus-mojotomcat-maven-plugin1-1deploy-default/16292897#16292897 – sancho21 Apr 30 '13 at 05:43

4 Answers4

6

The following way works for me.

  1. Please change your pom.xml to include

    <project>
        ...
        <build>    
            <plugins>    
            ....
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <url>http://localhost:8080/manager/text</url>
                        <server>my-tomcat</server>
                        <path>/myapp</path>
                    </configuration>
                </plugin>
            </plugins>
            ...
        </build>
        ...
    </project>
    
  2. Make sure your Tomcat 7 server have the following lines on TOMCAT_HOME/conf/tomcat-users.xml:

    <!-- Role to manage WAR files via HTML /manager. The name should be as is! -->
    <role rolename="manager-gui"/>
    <!-- Role to manage WAR files via script like Maven. The name should be as is! -->
    <role rolename="manager-script"/>
    
    <!-- One user cannot have manager-gui and manager-script roles -->
    <user username="managerGui" password="managerPwd" roles="manager-gui"/>
    <user username="manager" password="managerPwd" roles="manager-script"/>
    
  3. Configure your USER_HOME/.m2/settings.xml to include the password.

    <settings>
        ...
        <servers>
            ...
            <server>
                <id>my-tomcat</id>
                <username>manager</username>
                <password>managerPwd</password>
            </server>
        </servers>
    
    </settings>
    
  4. Deploy using mvn tomcat7:redeploy

Read more on http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html

sancho21
  • 3,511
  • 1
  • 39
  • 45
3

try to run mvn with -x -e then you will see what kind of info is sending to server. my guess is that the server doesnt get username/pass. which means something wrong with the configuration file i.e:settings.xml

how does tomcat7-maven-plugin knows where settings.xml is ?

EDIT: check out this which-maven-settings-xml-files

elek offered there to run mvn with -X and in the begining you see "Reading user settings from .user/.m2/settings.xml..

Community
  • 1
  • 1
oak
  • 2,898
  • 2
  • 32
  • 65
  • Indeed this was the issue. Settings xml was taken from different location. I assumed the correct one to be used is from C:\.m2\settings.xml, however the one from C:\users\.m2 was taken. Thx for help – Arek Nov 12 '12 at 09:36
1

mvn tomcat7:redeploy -Dtomcat.username=tomcatscript -Dtomcat.password=s3cret

works as well.

Todd
  • 2,829
  • 5
  • 34
  • 56
0

You should declare all the roles in the tomcat-users.xml:

<role rolename="tomcat"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="admin"/>
<role rolename="manager-script"/>

HIH

poussma
  • 7,033
  • 3
  • 43
  • 68
  • remove the trailing spaces in the roles="..." – poussma Nov 06 '12 at 13:51
  • 1
    can you connect to http://localhost:8081/manager/text ? do you see FAIL - Unknown command /text ? Have you the UserDatabase configured in the server.xml ? – poussma Nov 06 '12 at 14:07