1. Tomcat7 user and permission configuration
To implement hot deployment, you naturally need to operate tomcat through maven, so maven needs to obtain permission to operate tomcat. Now this step is to configure the operational permissions of tomcat.
In the tomcat installation directory, modify the conf / tomcat-user.xml file and add the following configuration under the <tomcat-users> node:
<role rolename="manager-gui" /> <role rolename="manager-script" /> <user username="tomcat" password="tomcat" roles="manager-gui, manager-script" />
2. Maven's server configuration
Find the installation path of Maven, modify the D:/develop_tools/maven/apache-maven-3.3.9/conf /setting.xml file, and add the user information configured under tomcat7 in the <server> node (id can be filled in at will, but username and password must be the same as step 1)
<server> <id>tomcat7</id> <username>tomcat</username> <password>tomcat</password> </server>
3. Configuration of web project pom.xml
3.1. Configuration of the official tomcat plug-in of apache
Tomcat7 configuration:
<plugins> <!-- The first method: apache official tomcat plugin, supports deploy --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.0-SNAPSHOT</version> <configuration> <url>http://localhost:8080/manager/text</url> <server>tomcat7</server> </configuration> </plugin> </plugins>
3.2 Third-party tomcat plug-in, support redeploy
Tomcat7 configuration:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <version>1.1</version> <configuration> <url>http://localhost:8080/manager/text</url> <server>tomcat7</server> <ignorePackaging>true</ignorePackaging> </configuration> </plugin>
3.3 Configuration of maven repository (this is optional):
<repository> <id>people.apache.snapshots</id> <url>http://repository.apache.org/content/groups/snapshots-group/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> <pluginRepository> <id>apache.snapshots</id> <name>Apache Snapshots</name> <url>http://repository.apache.org/content/groups/snapshots-group/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository>
4. Set deployment commands
Generally, search is in eclipse. You can right-click on the project you need to deploy. Run as -> Run configurations -> maven build -> right-click new, so as to configure a new maven command
Specific configuration command method:
1. Select your own project in the base directory
2.Goals configuration
If you use the official plugin of apache, then use the "tomcat7:deploy" command
If you use a third-party plug-in, then use the "tomcat:redeploy" command
5. Related errors and solutions:
Connection refused error
The error message is as follows:
[ERROR]Failed to execute goal org.apache.tomcat.maven: tomcat7-maven-plugin: 2.0- SNAPSHOT: deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Connection refused: connect -> [Help 1]
Cause: The Tomcat server was not started
Solution: Start Tomcat server first and then select Run
undeploy failed
Execute under Window system When executing mvn tomcat7:undeploy, it will remain in the tomcat directory
Workaround: Add attribute to the <Context> tag in tomcat's configuration file context.xml: antiJARLocking="true"
antiResourceLocking=”true”
Right now
<Context antiJARLocking="true" antiResourceLocking="true">
401 Error
The error message is as follows:
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin: 2.0-SNAPSHOT:deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/text/deploy?path=%2Fhelloworld -> [Help 1]
Cause: Permission issues
Solution in $CATALINA_BASE/conf/tomcat-users.xml,
For example, add permissions in the D:/apache-tomcat-7.0.34/conf/tomcat-users.xml file
<role rolename=”manager”/><user username=”admin” password=”admin” roles=”manager”/>
Modify the pom.xml file and add it in <configuration> </configuration>
<username>admin</username><password>admin</password>
403 Error
The error message is as follows:
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin: 2.0-SNAPSHOT:deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/html/deploy?path=%2Fhelloworld -> [Help 1]
Cause: There are two reasons for this problem. See the solution for details.
Solution:
1) If you are using Tomcat 7, you need to modify the URL address deployed in pom.xml, and change <url>http://localhost:8080/manager</url> to <url>http://localhost:8080/manager/text</url>
2) To assign the permissions to tomcat users, you need to have both manager-gui and manager-script permissions. When I encountered this problem, I forgot to assign manager-script permissions.
The correct conf/tomcat-users.xml configuration should be:
<tomcat-users><role rolename="manager-gui"/><role rolename="manager-script"/><user username="admin" password="admin" roles="manager-gui, manager-script"//</tomcat-users>
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.