問題
在Java Web開發中,不像PHP等方便,在更新了Java文件后,一般要手動進行Compile->Redeploy(或重啟)這兩個步驟,浪費不少生命--時間就是生命啊!!。特別是在開發較大應用的時候,那個心塞的...沒辦法既然選擇了java,那就得編譯。對Java那是又愛又恨啊。雖然開發久了可以稍微避免不必要的編譯。但那也是在浪費生命。更換IDEA是一個不錯的選擇,針對修改-->編譯-->刷新瀏覽器的漫長等待中,今天嘗試了java的熱部署,確實方便了很多!!
JRebel是一款Java虛擬機插件,它使得我們能在不進行重部署的情況下,即時看到代碼的改變對一個應用程序帶來的影響。JRebel使你能即時分別看到代碼、類和資源的變化,你可以一個個地上傳而不是一次性全部部署。
一、使用Intellij IDEA手動熱部署
1、Run->Edit Configurations...
當修改了代碼以后,編譯代碼(一般都設置自動編譯),然后手動點擊下圖的Deploy All按鈕,Ctrl+F9來重新編譯 ,這個相比較每次都重啟Tomcat已經好多了。
二、使用JRebel插件實現熱部署
1、首先得安裝Jrebel插件
點擊Apply 然后重啟啟動
2.激活Jrebel,說道激活Jrebel,網上有很多教程的教程和下載版本,但這個激活是最方便的,https://blog.kuoruan.com/62.html,感謝高人提供的方便快捷
http://idea.lanyus.com/img/JRebel.png
1 2016-05-09 18:13:54 JRebel: 2 2016-05-09 18:13:54 JRebel: A newer version '6.4.3' is available for download 3 2016-05-09 18:13:54 JRebel: from http://zeroturnaround.com/software/jrebel/download/ 4 2016-05-09 18:13:54 JRebel: 5 2016-05-09 18:13:54 JRebel: Found offline lease from local storage.. executing JRebel with offline licensing. 6 2016-05-09 18:13:54 JRebel: 7 2016-05-09 18:13:54 JRebel: ############################################################# 8 2016-05-09 18:13:54 JRebel: 9 2016-05-09 18:13:54 JRebel: JRebel Agent 6.0.2 (201412191331) 10 2016-05-09 18:13:54 JRebel: (c) Copyright ZeroTurnaround AS, Estonia, Tartu. 11 2016-05-09 18:13:54 JRebel: 12 2016-05-09 18:13:54 JRebel: Over the last 1 days JRebel prevented 13 2016-05-09 18:13:54 JRebel: at least 3 redeploys/restarts saving you about 0 hours. 14 2016-05-09 18:13:54 JRebel: 15 2016-05-09 18:13:54 JRebel: License acquired from License Server: http://idea.lanyus.com 16 2016-05-09 18:13:54 JRebel: 17 2016-05-09 18:13:54 JRebel: Licensed to ilanyu. 18 2016-05-09 18:13:54 JRebel: 19 2016-05-09 18:13:54 JRebel: You are using an offline license. 20 2016-05-09 18:13:54 JRebel: 21 2016-05-09 18:13:54 JRebel: 22 2016-05-09 18:13:54 JRebel: ############################################################# 23 2016-05-09 18:13:54 JRebel:
另附在線獲取idea驗證碼和幫助的URL 和給力 http://idea.lanyus.com/
如果報java.lang.OutOfMemoryError: PermGen space,需設置VM options,設置“-XX:MaxPermSize=1024m -Dfile.encoding=UTF-8”,JReble無需配置就可以實現熱重啟,前提是需要將Tomcat的配置“On frame deactivation”從”Do nothing”改成”Update classes and resources”。
三、Jrebel不起作用的解決辦法
感謝:
http://www.cnblogs.com/wql025/p/5017823.html
https://blog.kuoruan.com/62.html
http://cnitzone.com/blog/2015/06/idea-hot-deploy/