一、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
3)部署項目
● 部署方式一:通過手動上傳的方式
1.登錄Manager App
2.上傳war包 部署
● 部署方式二:通過 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:deploy 或 tomcat7:redeploy 來進行熱部署
tomcat7:deploy:第一次部署時使用。
tomcat7:redeploy:非第一次部署時使用。
4)部署完畢,打開瀏覽器測試
Manager App查看部署項目
Running狀態為true的表示已經部署上去了。