一、Tomcat中配置${CATALINA_HOIME}/conf/tomcat-users.xml
配置为如下内容
<tomcat-users xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
version="1.0">
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="admin" password="admin" roles="admin-gui,manager-gui,manager-status"/>
<user username="tomcat" password="tomcat" roles="manager-script"/>
</tomcat-users>
二、为了能够远程登录manager页面,在目录${CATALINA_HOIME}/conf/Catalina/localhost
下创建manager.xml
,并添加如下内容
<Context privileged="true" antiResourceLocking="false"
docBase="${catalina.home}/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>
配置完成后就可以在网页登陆远程管理Tomcat应用了
三、在Maven的settings.xml
中配置server节点
此处的用户名密码就是${CATALINA_HOIME}/conf/tomcat-users.xml
中配置的用户名密码
<server>
<id>tomcat8</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
四、maven项目pom.xml配置
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://IP:PORT/manager/text</url>
<server>tomcat8</server>
<path>/${project.name}</path>
</configuration>
</plugin>
</plugins>
如果Maven的settings.xml
配置文件中没有配置server节点,还可配置如下
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://IP:PORT/manager/text</url>
<!-- ${CATALINA_HOIME}/conf/tomcat-users.xml中配置的用户名密码 -->
<username>tomcat</username>
<password>tomcat</password>
<path>/${project.name}</path>
</configuration>
</plugin>
</plugins>
五、Maven tomcat7插件基本命令
-
远程部署
mvn tomcat7:deploy
运行结果:
[INFO] <<< tomcat7-maven-plugin:2.2:redeploy (default-cli) < package @ file_system_mgt <<<
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:redeploy (default-cli) @ file_system_mgt ---
[INFO] Deploying war to http://IP:PORT/File_System_Mgt
Uploading: http://IP:PORT/manager/text/deploy?path=%2FFile_System_Mgt&update=true
Uploaded: http://IP:PORT/manager/text/deploy?path=%2FFile_System_Mgt&update=true (26207 KB at 228.8 KB/sec)
[INFO] tomcatManager status code:200, ReasonPhrase:
[INFO] OK - Deployed application at context path /File_System_Mgt
-
远程重部署
mvn tomcat7:redeploy
运行结果:
[INFO] <<< tomcat7-maven-plugin:2.2:deploy (default-cli) < package @ file_system_mgt <<<
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:deploy (default-cli) @ file_system_mgt ---
[INFO] Deploying war to http://IP:PORT/File_System_Mgt
Uploading: http://IP:PORT/manager/text/deploy?path=%2FFile_System_Mgt
Uploaded: http://IP:PORT/manager/text/deploy?path=%2FFile_System_Mgt (26207 KB at 220.1 KB/sec)
[INFO] tomcatManager status code:200, ReasonPhrase:
[INFO] OK - Deployed application at context path /File_System_Mgt
-
远程卸载
mvn tomcat7:undeploy
运行结果:
[INFO] --- tomcat7-maven-plugin:2.2:undeploy (default-cli) @ file_system_mgt ---
[INFO] Undeploying application at http://IP:PORT/File_System_Mgt
[INFO] OK - Undeployed application at context path /File_System_Mgt