一、Tomcat热部署

热部署是在 tomcat 运行时将项目部署上去,原来我们是在服务器关闭状态下将项目部署上去,然后再启动服务器。

在学习热部署之后,我们可以在服务器启动的时候随时随刻部署上去,无需关闭服务器。

下面使用 maven3.6.3 + tomcat8.5 进行热部署 ????

二、开启tomcat热部署

1)修改 tomcat 配置文件

文件路径:tomcat根目录 -> conf -> tomcat-users.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
    
    <!-- 开启Tomcat热部署 -->
    <role rolename="manager-gui"/>
    <role rolename="manager-script"/>
    <role rolename="manager-jmx"/>
    <role rolename="manager-status"/>
    <user username="alin" password="123123" roles="manager-status,manager-gui,manager-script,manager-jmx"/>

</tomcat-users>

2)启动tomcat

tomcat根目录 -> bin -> startup.bat

Maven - Tomcat8.5热部署

3)部署项目

● 部署方式一:通过手动上传的方式

1.登录Manager App

Maven - Tomcat8.5热部署

 2.上传war包 部署

Maven - Tomcat8.5热部署

部署方式二:通过 Eclips 命令的方式

1.修改项目中pom.xml - 在tomcat7的插件上添加以下代码

<!-- tomcat7的插件 -->
<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>${tomcat7-maven-plugin.version}</version>
    <configuration>
     <!-- tomcat7路径在test目录 ,7以下没有test -->
        <url>http://localhost:8080/manager/text</url>
        <username>alin</username>
        <password>123123</password>
    </configuration>
</plugin>

2.右键项目 -> Run as -> Maven build… 在 Goals 中使用 tomcat7:deploytomcat7:redeploy 来进行热部署

tomcat7:deploy:第一次部署时使用。
tomcat7:redeploy:非第一次部署时使用。

Maven - Tomcat8.5热部署

4)部署完毕,打开浏览器测试

Manager App查看部署项目

Maven - Tomcat8.5热部署

Running状态为true的表示已经部署上去了。

相关文章:

  • 2021-12-10
  • 2021-06-18
  • 2021-10-03
  • 2021-12-13
  • 2022-01-18
猜你喜欢
  • 2021-12-02
  • 2022-12-23
  • 2021-04-01
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
相关资源
相似解决方案