Tomcat7 maven plugin deployment

I am having problems deploying to a remote machine with tomcat installed as aservice. My tomcat users:

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

My .xml settings:

 <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 getting 401 Unauthorized on the maven console output. Can you tell me what I'm doing wrong?

+4
source share
4 answers

try running mvn with -x -e you will see what information is sent to the server. I assume the server is not getting username / password. something is wrong with ie: settings.xml configuration file

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

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

elek suggested there to run mvn with -X and at the beginning you see "Reading user settings with .user / .m2 / settings.xml ..

+3
source

The following method works for me.

  • Modify 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> 
  • Make sure your Tomcat 7 server has the following lines at 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"/> 
  • Configure your USER_HOME/.m2/settings.xml to enable the password.

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

Learn more about http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html

+6
source

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

also works.

+1
source

You must declare all roles in tomcat-users.xml:

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

E.I.V.

0
source

Source: https://habr.com/ru/post/1444319/


All Articles