JRebel Eclipse熱部署教程
阿新 • • 發佈:2018-12-26
JRebel+Eclipse熱部署教程
在開發web專案時,常常修改很少的程式碼(例如配置檔案或java程式碼)就需要重啟伺服器,來檢視修改後的效果。如果專案比較大,重啟一次伺服器幾十秒,這簡直就是噩夢!
好在JRebel這個神器的存在,使得我們可以在修改程式碼後進行熱部署,即不需要重啟伺服器,就可以檢視修改後的效果!
下面記錄一下JRebel的安裝教程和使用方法。
Eclipse下JRebel的安裝
- 開啟Eclipse—->Help—->EclipseMarketplace
- 在搜尋框輸入jrebel,回車搜尋
- 安裝完成後,eclipse右上角會多出一個檢視選項,同時Help選單中也多出一個JRebel的選單
- 點選Help—->JRebel—->Activation進入啟用介面
- 啟用完成後,JRebel已經預設配置好了。
現在開始使用JRebel執行專案:- 右鍵點選你要使用JRebel的專案,會出現JRebelR選項,點選Add JRebel Nature,點選後src下會多出一個配置檔案rebel.xml [選這個這個是為了可以監聽你專案中class檔案的變化,如果你修改了java程式碼,生成新的class後會被重新載入]
- 可以執行專案了,右鍵專案,點選Run As—->Run Configuration,配置執行引數,然後Run
- 看控制檯,出現以下內容說明JRebel監控成功:
2017-11-24 21:39:52 JRebel: Directory 'C:\Users\hasee\oxygen-workspace\crm01\build\classes' will be monitored for changes. 2017-11-24 21:39:52 JRebel: Directory 'C:\Users\hasee\oxygen-workspace\crm01\WebContent' will be monitored for changes. 2017-11-24 21:39:55 JRebel: Starting logging to file: C:\Users\hasee\.jrebel\jrebel.log 2017-11-24 21:39:55 JRebel: 2017-11-24 21:39:55 JRebel: ############################################################# 2017-11-24 21:39:55 JRebel: 2017-11-24 21:39:55 JRebel: JRebel Agent 7.1.2 (201711071615) 2017-11-24 21:39:55 JRebel: (c) Copyright ZeroTurnaround AS, Estonia, Tartu. 2017-11-24 21:39:55 JRebel: 2017-11-24 21:39:55 JRebel: Over the last 2 days JRebel prevented 2017-11-24 21:39:55 JRebel: at least 6 redeploys/restarts saving you about 0.2 hours. 2017-11-24 21:39:55 JRebel: 2017-11-24 21:39:55 JRebel: Licensed to fly fly (using myJRebel). 2017-11-24 21:39:55 JRebel: 2017-11-24 21:39:55 JRebel: 2017-11-24 21:39:55 JRebel: ############################################################# 2017-11-24 21:39:55 JRebel: 2017-11-24 21:39:55 JRebel: Monitoring Log4j configuration in 'file:/C:/Users/hasee/oxygen-workspace/crm01/build/classes/log4j.properties'. 十一月 24, 2017 9:39:55 下午 org.apache.catalina.core.ApplicationContext log 資訊: Initializing Spring root WebApplicationContext 21:39:55,852 INFO ContextLoader:304 - Root WebApplicationContext: initialization started 21:39:55,979 INFO XmlWebApplicationContext:583 - Refreshing Root WebApplicationContext: startup date [Fri Nov 24 21:39:55 CST 2017]; root of context hierarchy 2017-11-24 21:39:56 JRebel: Monitoring Spring bean definitions in 'C:\Users\hasee\oxygen-workspace\crm01\build\classes\applicationContext.xml'. 21:39:56,197 INFO XmlBeanDefinitionReader:317 - Loading XML bean definitions from class path resource [applicationContext.xml] 2017-11-24 21:39:56 JRebel: Monitoring properties in 'file:/C:/Users/hasee/oxygen-workspace/crm01/build/classes/druid.properties'.
- 這裡說明class檔案和webcontent中的檔案會被監視,如果發生改變則會重新部署
- 這裡說明spring配置檔案applicationContext.xml和德魯伊連線池配置檔案會被監聽
- 測試下,修改一段程式碼,給Action中加一個方法
/*********************************** * Test JRebel * @return ***********************************/ @Action(value = "test", results = { @Result(name = "test", location = "customer_list", type = "redirectAction") }) public String testJRebel() { System.out.println("Hello JRebel"); return "test"; }
- 看到控制檯輸出:
2017-11-24 21:45:43 JRebel: Reloading class 'com.fly.action.CustomerAction'.
- 右鍵點選你要使用JRebel的專案,會出現JRebelR選項,點選Add JRebel Nature,點選後src下會多出一個配置檔案rebel.xml [選這個這個是為了可以監聽你專案中class檔案的變化,如果你修改了java程式碼,生成新的class後會被重新載入]
補充
如果安裝完成後專案無法啟動,報錯:
JRebel-JVMTI [FATAL] A fatal error occurred while proccessing the base java classes. The JVM has been shut down...
極有可能是以下原因:
- eclipse所在路徑包含中文!
- 當前系統使用者資料夾包含中文
JRebel 對Springboot的熱部署支援
JRebel 已經能夠支援Springboot專案的熱部署了。
但是好像JRebel 只能支援到Spring4.x
Springboot的2.0.0版本使用了Spring5.0.4
使用JRebel 熱部署2.0.0的專案時會報錯