有一天一个人问题,maven怎么实现热部署。我不太了解,我以为是热加载,就像jrebel 但是后来经过查阅才发现热加载和热部署同源,但是确实不同的功能。

我们编写项目,特别是测试的项目,如果经常的更新,很是麻烦,tomcat8实现了将本地的服务,自动部署到服务器上,而且不需要重启tomcat感觉是不是很牛

那么ecplise maven项目如何实现热部署,咱们下面就来聊一聊

1.首先我们有一个maven项目:

tomcat8 热部署_java

 项目已经准备好

2. 我们实现的是远程的部署,需要一台服务器,我们也可以找本地的127.0.0.1 ,或者是linux 服务器。接下来我们我们需要下载tomcat

我们服务器选择linux 服务器,然后我们需要下载tomcat:

tomcat8 热部署_tomcat_02

 下载之后上传到服务器,并且解压,启动之后我们能正常打开ip:8080

3.  添加tomcat 用户 ,在解压的tomcat目录 /conf目录下面有tomcat-users.xml 这个文件

tomcat8 热部署_服务器_03

 我们编辑这个文件,新增如下:

tomcat8 热部署_java_04

  <role rolename="manager-gui" />
<role rolename="manager-script" />
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script" />

用户添加好了之后,如果我们是远程部署的,需要我们能够访问到服务器上的manager这个项目,如何才能访问,这个项目除了本地之外,其他的ip都需要添加白名单

在webapps/manager/META-INF/context.xml

我们需要增加上我们的电脑ip

百度ip查询:

tomcat8 热部署_服务器_05

把上面的ip复制下来,然后编辑context.xml文件

tomcat8 热部署_maven_06

上面打马赛克的是你自己的ip地址;

4. 接下来配置ecplise

window----->preference--->Maven--->settings.xml 配置

<server>
<id>tomcat7</id>
<username>tomcat</username>
<password>tomcat</password>
</server>

 5.配置pom.xml

      <finalName>ROOT</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<url>http://*******:8080/manager/text</url>
<server>tomcat7</server>
<path>/ROOT</path>
<update>true</update>
<uriEncoding>UTF-8</uriEncoding>
<username>tomcat</username> <!--之前设置的用户名-->
<password>tomcat</password> <!--之前设置的密 -->
</configuration>
</plugin>
</plugins>

和:

      <!--自动部署  -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>8.5.4</version>
</dependency>

 打包:

tomcat8 热部署_maven_07

完成 访问服务器上的ip:8080就是你的ecplise,上面的项目

希望对你有所帮助