idea maven tomcat 热部署
背景
上一篇 tomcat + nginx 部署各类工程的几种方式 中提到 只用 tomcat 自带的 manager 工程进行外网部署管理。后续上网发现,还有更简洁、高效的方式可以部署。即这篇文章,在 maven 中使用 tomcat 的插件进行部署。这样就可以不用登录 manager 管理页面操作,只需要点以下即可。
技能列表
- 在 maven 中使用 tomcat 的插件进行部署
在 maven 中使用 tomcat 的插件进行部署
直接上干货—配置文件。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.taotao</groupId>
<artifactId>taotao-manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>taotao-manager-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<!-- 依赖管理 -->
<dependencies>
<dependency>
<groupId>com.taotao</groupId>
<artifactId>taotao-manager-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- JSP相关 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- 文件上传组件 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<debug>true</debug>
<optimize>false</optimize>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<!-- 配置Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<!--
一般eclipse启动项目时候这里配置什么端口,访问项目的时候就是什么端口;用了热部署后,
是部署到目标tomcat里,因此这个port算是没用,访问时,是在tomcat的端口
-->
<!-- 默认部署在 tomcat/webapps 下 -->
<port>8080</port>
<!-- path 为启动的上下文更 -->
<path>/taotao-manager-web</path>
<!-- tomcat的地址和端口,manager/text是固定的 -->
<url>http://47.99.69.84:8080/manager/text</url>
<!-- 支持热更新,没有这个会发生啥不知道。建议加上-->
<update>true</update>
<username>tomcat</username>
<password>tomcat</password>
</configuration>
</plugin>
</plugins>
</build>
</project>
配置 pom.xml 之后。在 idea 的右侧,如图: 点击此处的命令即可
验证结果
则开始进行热部署替换。命令进度如下 则表示成功上传。上下文根目录为 path
可以看 列表 或者 message