1: Configure the Tomcat Manager User:
Re-unzipped a new TOMCAT7, open Tomcat_user.xml in the Conf directory under the Tomcat root directory, add Manager roles and users under <tomcat-users> node for Tomcat Maven Plugin automatically deploys the application with the following XML code:
<tomcat-users> <role rolename= "Manager-gui"/> <role rolename= "Manager-script"/> <user username= "Alexgaoyh" password= "Alexgaoyh" roles= "Manager-gui, Manager-script"/> <!--username and password can be other character string --></tomcat-users>
Adding Tomcat Server to the 2:maven configuration
Open maven's settings.xml file, if it is a locally installed version of MAVEN, the file is installed in the root directory conf/settings.xml, if you are using the eclipse built-in maven, the file is the current system user Directory/ . M2/setting.xml. Configure the manager user information for Tomcat under the <servers> node, with the following XML code:
<servers> <server> <id>Tomcat7</id> <username>alexgaoyh</username > <password>alexgaoyh</password> </server><servers>
The ID is used to configure the server in the Pom.xml file, with the user name and password Tomcat_user.xml in the same configuration.
3: Add the Tomcat Service to the MAVEN project:
Open the Project Pom.xml file and add the Tomcat Maven plugin plugin under the <plugins> node with the following XML code:
<build><finalName>web</finalName><plugins><plugin> <groupId> Org.apache.tomcat.maven</groupid> <artifactId>tomcat7-maven-plugin</artifactId> <version >2.2</version> <configuration> <url>http://localhost:8080/manager/text</url> <!-- The Tomcat management path--><server>tomcat7</server> <!--is the same as the server ID in the settings.xml file--><path>/web </path> < deployment location for!--applications--></configuration> </plugin></plugins></build>
4: Deploy to TOMCAT7:
Select the project in Project view, right-click "Run as", "Maven bulid", execute Tomcat7:deploy command, you can complete the deployment, execute tomcat7:redeploy to redeploy the project, andtomcat7:undeploy Uninstall the deployment.
Problems encountered:
Connection refused error
[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
Maven Tomcat7-maven-plugin deploying MAVEN Web projects