Maven Tomcat plugin for hot deployment

Source: Internet
Author: User
Tags response code

Objective:

The method here is applicable to Tomcat6 and TOMCAT7, for the latest TOMCAT8 has not been tested, interested students can be measured by themselves.

The total is divided into five steps:

1. Configure user rights in Tomcat, i.e. add Administrator account

2. Add the server in MAVEN and configure the Tomcat Administrator account password

3. Add the plug-in to project and the server configured in Maven,

4. Setting up Deployment commands

5. Deploy

Related Errors and Solutions

Here are a few steps to explain:

I. To configure user rights in Tomcat, add an administrator account.

We need to implement a hot deployment and naturally need to work with Tomcat through MAVEN, so we need maven to get permission to manipulate Tomcat, and now this is a step to configure the operational permissions of Tomcat.

Under the Tomcat installation directory, modify the Conf/tomcat-user.xml file to 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 "/>


Two. Add the server in MAVEN and configure the Tomcat Administrator account password

Now that Tomcat is enabled, MAVEN will have to get Tomcat's admin account and password to work with Tomcat.

Under MAVEN's installation directory, modify the Conf/setting.xml file. Add the following configuration under the <server> node:

<server>         <id>admin</id>         <username>tomcat</username>         <password> Tomcat</password>  </server>  


three. Add the plug-in to project and the server configured in Maven,

MAVEN now has permission to manipulate Tomcat, but there is also a bridge between the two to communicate, which is to configure the Tomcat plugin in maven.

Modify the project's Pom.xml file to add the following configuration under the <build> node:

<plugins ><!--The first way: Apache official Tomcat plugin, support for 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>admin</ server></configuration></plugin><!--Second way: third-party tomcat plugin, support redeploy--><plugin>< groupid>org.codehaus.mojo</groupid><artifactid>tomcat-maven-plugin</artifactid>< Version>1.1</version><configuration><url>http://localhost:8080/manager/text</url> <server>admin</server><ignorePackaging>true</ignorePackaging></configuration> </plugin></plugins> 
for the above plug-ins, there are two online, after testing can be used, but note that the above configuration can only be used for TOMCAT7, if you want to use TOMCAT6, you need to configure the following way:

<plugins><!--Apache official Tomcat plugin, support for deploy--><plugin><groupid>org.apache.tomcat.maven</ Groupid><artifactid>tomcat6-maven-plugin</artifactid><version>2.0-snapshot</version ><configuration><url>http://localhost:8080/manager/html</url><server>admin</ server></configuration></plugin><!--third-party tomcat plug-ins that support redeploy--><plugin><groupid >org.codehaus.mojo</groupId><artifactId>tomcat-maven-plugin</artifactId><version> 1.1</version><configuration><url>http://localhost:8080/manager</url><server> Admin</server><ignorepackaging>true</ignorepackaging></configuration></plugin> </plugins>
whether it's tomcat7 or TOMCAT6, just use one of the plugins. But there's a difference between the two types of plugins:

The first is the official Apache plug-in, support for the Deploy command, if deployed to the Tomcat container, the second deployment will be an error, indicating that the project has been deployed.

The second is a third-party plug-in that can be deployed repeatedly using the redeploy command
At the same time, please add the warehouse configuration under the <project> node, or the plugin may not be found, resulting in an error:

<repositories><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></repositories><pluginrepositories><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></ Pluginrepositories>



Four. Setting up deployment commands

General use Search is in Eclipse, you can right-click on the project you need to deploy, run as---run configurations------Maven build, right-click New, to configure a fresh Maven

Specific configuration command methods:

1. Select your own project in base directory

Configuration of 2.Goals

If you use Apache's official plugin, then use the "tomcat7:deploy" command

If you use a third-party plug-in, then use the "tomcat:redeploy" command


Five. Deploy

Right-click your own project, Run as--Maven build.

Note:

Some students are not accustomed to using the IDE, so it is the same with MAVEN implementation on the command line.

From the command line into your own project folder, use the MVN command, for example: MVN tomcat7:deploy


Related Errors and solutions:

1.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 Hello World:cannot invoke Tomcat manager:connection refused:connect [Help 1]
Cause: The tomcat server is not started
Workaround: First start the Tomcat server and select Run


2.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/t Ext/deploy?path=%2fhelloworld, [Help 1]
Cause: Permission Issues
Solution in $catalina_base/conf/tomcat-users.xml,
Add permissions like 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>


3.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/h Tml/deploy?path=%2fhelloworld, [Help 1]
Cause: The problem is likely to occur for two reasons, see the solution specifically
Workaround:
1) If you are using Tomcat 7, you need to modify the URL address of the deployment in Pom.xml, and change <url>http://localhost:8080/manager</url> to <url>http:// Localhost:8080/manager/text</url>
2) to the Tomcat user rights assignment, need to have both Manager-gui and Manager-script permissions, I encountered this problem, is to forget 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>



Maven Tomcat plugin for hot deployment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.