1. Environment preparation
The environment I use is: Window 10, Tomcat 8.0.36, maven3, tomcat7-maven-plugin version 2.2.
2. Setting environment variables
After installing Tomcat8.0.36 and maven, set environment variables. When Tomcat sets environment variables, the key must be CATALINA_HOME.
1. Set maven environment variable
MAVEN =D:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.1.3\plugins\maven\lib\maven3\bin
(I directly quoted maven in InteljiIDEA)
2. Set TOMACAT environment variable
CATALINA_HOME=E:\tomcat\apache-tomcat-8.0.36
3. Add them to PATH
PATH=%MAVEN%;%CATALINA_HOME%\bin;
3. Configure user permissions
in Tomcat Add to the < tomcat-users > tag in the tomcat configuration file tomcat_user.xml (%CATALINA_HOME%\conf\tomcat.user.xml)
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="username" password="password" roles="manager-gui,manager-script"/>
- 1
- 2
- 3
4. Configure Server
in Maven's settings.xml Add in <servers> in Maven's configuration file settings.xml (%MAVEN%\conf\settings.xml)
<server>
<id>tomcat8</id>
<username>username</username>
<password>password</password>
</server>
- 1
- 2
- 3
- 4
- 5
The username and password here are filled with the username we configured in tomcat, and
the id set here for the password is tomcat8, which we will fill in the pom.xml of the project.
5. Configure the tomcat7-maven-plugin plugin in the pom.xml of the project. Introduce
the plugin in <build>:
<build>
<pluginManagement>
<plugins>
...
<!-- 配置tomcat 插件 -->
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>tomcat8</server>
<path>/test</path>
<update>true</update>
</configuration>
</plugin>
</plugins>
</pluginManagement>
....
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
Note
1. The < server> here is filled with the id in the %MAVEN%\conf\settings.xml configuration, which
is tomcat8.
2. Since the tomcat8 I use, the <url> here must be configured as xxx/manager /text otherwise the deployment will fail
3. Since some things will be downloaded during deployment, it is best to add the following code under the <project> tag of pom.xml:
<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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
Six, deploy
1. Open tomcat
2. Execute the mvn tomcat7:deploy command in the directory where pom.xml is located to deploy the project.
7. Problems encountered
1. When executing mvn tomcat7:undeploy under the Window system, there will be residues in the tomcat directory.
Solution: Add the attribute to the <Context> tag in the tomcat configuration file context.xml: antiJARLocking =”true” antiResourceLocking=”true”
i.e.
<Context antiJARLocking="true" antiResourceLocking="true">
转载来自:https://blog.csdn.net/a992036795/article/details/53063962
参考:https://blog.csdn.net/a992036795/article/details/53063962