Direct deployment of Web applications to Tomcat using Maven
1. Download and decompress Tomcat and configure environment variables so that Tomcat can be started successfully.
The decompressed version of tomcat allows you to conveniently view error information output by tomcat in the background for debugging.
2. Configure the username and password for tomcat.
Modify the/config/tomcat-user.xml under the tomcat installation directory to the following:
<?xml version='1.0' encoding='cp936'?><tomcat-users><role rolename="manager-gui"/> <role rolename="manager-script"/> <user username="username" password="password" roles="manager-gui,manager-script"/></tomcat-users>
The preceding configuration file is used to add a user named "username", "password", and "manager-gui" to tomcat.
3. Add the following code to the pom. xml file of the maven project.
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <url>http://localhost:8080/manager/text</url> <username>username</username> <password>password</password> <path>/${project.artifactId}</path> </configuration> </plugin> </plugins>
4. Deploy the application
If eclipse is used, right-click the project and choose Run As> Maven build... -> Enter Tomcat 7: deploy in Goals;
If Maven is used directly, run the following command:
mvn tomcat7:deploy
Maven official guide _ Chinese full version clear PDF
Maven 3.1.0 release, Project Build Tool
Install Maven in Linux
Maven3.0 configuration and simple use
Set up sun-jdk and Maven2 in Ubuntu
Get started with Maven
This article permanently updates the link address: