1

POM.xml:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>tomcat-maven-plugin</artifactId>
    <configuration>
        <url>http://localhost:8080/manager/html</url>
        <server>myserver</server>
        <path>/test</path>
        <warFile>${project.build.directory}/${project.build.finalName}.war</warFile>
    </configuration>
</plugin>

Eclipse used: Eclipse indigo 3.7 with m2e plugin

modified Tomcat7/conf/tomcat-users.xml

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

Context.xml Tomcat7/conf/context.xml, change <context> to

<Context antiJARLocking="true" antiResourceLocking="true">

under apache-maven\conf\settings.xml

add following entry under server tag:

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

Start tomcat server.

target run: tomcat:deploy and tomcat:undeploy

getting following error:

[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:redeploy (default-cli) on project test: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/html/deploy?path=%2Ftest&war=&update=true -> [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

project name: test

war file name: test-1.0-SNAPSHOT.war

similar issue found but didnot get much use: Tomcat-maven-plugin 401 error

tomcat-maven-plugin 403 error

Community
  • 1
  • 1
TechFind
  • 3,696
  • 18
  • 47
  • 62

5 Answers5

6

Though a late answer , someone might find this useful. If you are using maven3 and tomcat7.The below method worked for me.I was not aware of the change in application manager endpoint in tomcat7.

Environment - Apache Maven 3.0.4,apache-tomcat-7.0.34,Windows 7

Tomcat7 has changed its deployment end point from http://tomcatserver:8080/manager/html to http://tomcatserver:8080/manager/text .

So my pom.xml will be

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

In tomcat-users.xml

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

  <user username="root" password="root" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>

In maven settings.xml

<server>
  <id>tomcat</id>
  <username>root</username>
  <password>root</password>
</server>

In context.xml , though this is optional and is not related to maven3 deployment to tomcat7 ,sometimes jar locking might happen,so to be on the safer side.

<Context  antiJARLocking="true" antiResourceLocking="true">

Now issue

mvn tomcat:deploy

Remember to start tomcat before maven deployment.

If deployment is success , your application will be available at

http://tomcatserver:8080/myWebApp
Tito
  • 8,894
  • 12
  • 52
  • 86
3

Add manager-gui to the roles:

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

And restart Tomcat.

Make sure that your XML configuration files are in use. A simple way to do this is writing an unclosed tag inside them and checking the error messages. If you don't get any error message you've written in an unused XML.

palacsint
  • 28,416
  • 10
  • 82
  • 109
  • 1
    after doing Manager-gui role, getting follwoing error:Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:redeploy (default-cli) on project test: Cannot invoke Tomcat manager: FAIL - Context /test is defined in server.xml and may not be undeployed [ERROR] FAIL - Application already exists at path /test – TechFind Sep 23 '11 at 08:10
  • Remove the ` – palacsint Sep 23 '11 at 08:20
  • when I do this changes application working fine. But if I do -mvn clean all server related xml files which I had modified( ie context.xml,server.xml, tomcat-users.xml)files are earsed and replaced as original file. why this is happening? – TechFind Sep 23 '11 at 10:25
  • I usually start Tomcat from command line with `bin/startup.bat`. I found this way more reliable than starting Tomcat from Eclipse. – palacsint Sep 23 '11 at 11:01
1

in tomcat 7 you should set

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

to deploy using maven plugin

maziar
  • 581
  • 3
  • 9
  • Thank you very very very much mate. I have been struggling to get this working for a couple of hours now. I've been getting a 403 error each time I tried to deploy and adding `manager-script` fixed it. – mlevit Feb 04 '13 at 05:12
0

For tomcat 7 you're using the wrong goals. Try tomcat7:deploy and tomcat7:undeploy instead.

Richard Vodden
  • 318
  • 3
  • 12
0

Found Quick Solution on Mentioned Website...

http://www.avajava.com/tutorials/lessons/how-do-i-deploy-a-maven-web-application-to-tomcat.html

Working as expected in Eclipse and Sprint Test Suite

Note :- I have used clean tomcat:deploy, worked perfectly for me.

Swarit Agarwal
  • 2,520
  • 1
  • 26
  • 33