提高開發效率-jrebel插件安裝

什麼是JRebel?

JRebel安裝一個javaagent監控系統中的classes和resources文件在工作空間的變化,然後在運行的應用服務器上熱加載這些變化,支持下面的這些類型的文件改變:
  • 改變Java classes文件.
  • 改變框架配置文件 (e.g. Spring XML files and annotations, Struts mappings, etc).
  • 任何靜態資源文件 (e.g. JSPs, HTMLs, CSSs, XMLs, .properties, etc)

JRebel 是

  • 一個節約開發時間的工具,能夠熱加載改變的代碼,不需要重新啓動容器或重新發布應用程序.
  • 一個JVM -javaagent 插件.-javaagent 是java5後的一個命令行屬性,JRebel使用插件方式安裝. 

JRebel 不是

  • 一個IDE插件.提供IDE插件是爲了改善用戶體驗,JRebel在普通的java編譯器和文本編輯器是一樣可以使用的.
  • 一個框架. JRebel不會在你的應用中引入任何依賴包. 你可以隨時隨地移除,不會影響你的開發.
  • 一個應用服務器. JRebel可以工作在所有優秀的應用服務器上.
  • 一個自定義的JVM. JRebel不需要改變JVM,它可以工作在所有基於JVM實現的優秀虛擬機.

簡單地說,它是JVM的一個插件 , 作爲java class 加載代理, 監控文件系統中.class文件的變動, 幫助實現類的熱加載.  在開發過程中, 可以省下可觀的 Tomcat重啓的時間.按年統計大約節省3到7周的時間 (官方數據) . 有了它, 你就可以像寫PHP代碼一樣, 邊修改邊測試!


JRebel怎麼工作的?

JRebel integrates with the JVM and application servers mainly on the class loader level. It does not create any new class loaders, instead, it extends the existing ones with the ability to manage reloaded classes.

When a class is loaded JRebel will try to find a corresponding .class file for it. It will search from the classpath (including an application classpath, like WEB-INF/classes) and from the places specified in the rebel.xml configuration file. If it find a .class file JRebel instruments the loaded class and associates it with the found .class file. The .class file timestamp is then monitored for changes in the loaded class and updates are propagated through the extended class loader, to your application. 
JRebel can also monitor .class files in JARs if they are specified in rebel.xml.

Importantly, when loading updates to a class, JRebel preserves all of the existing instances of that class. This allows the application to just continue working, but also means that when adding a new instance field it will not be initialized in the existing instances, since the constructor will not be rerun.

Some common misconceptions:

  • JRebel just wraps class loaders around classes. In fact JRebel does not add a single new class loader to your application. The solution of reloading Java classes by wrapping them in throwaway classloaders is a well-known one, but unfortunately also very limited. The problem is that unless you also throw away all of the instances of the classes loaded by said class loaders, the code will not reload. However throwing away those instances is only possible if they are somehow managed by the framework, e.g. as it's done in Tapestry 5.
  • JRebel just uses Instrumentation API. The Instrumentation API was introduced in Java 5 and included a limited ability to redefine Java classes on-the-fly. Unfortunately it is limited to only changing method bodies (as is HotSwap) and also suffers from several additional quirks, which makes it not too useful in a real environment. JRebel agent does use it to instrument the application server class loaders and other basic classes, but the API does not play part in the actual reloading process.

安裝Eclipse JRebel插件

1.1 Introduction

JRebel IDE plugins are available for Eclipse, IntelliJ IDEA and NetBeans and provide the following features:

Debugger
Support for debugging the application with JRebel agent enabled. Necessary to set breakpoints, inspect expressions and step through code.
Running with JRebel
Support for starting the application or server from withing the IDE with the JRebel agent enabled. [Missing in NetBeans and IntelliJ IDEA before 8.x]
rebel.xml generation
Support for generating the rebel.xml configuration file from the IDE project definition. [Missing in NetBeans and IntelliJ IDEA before 8.x]

1.2 Eclipse

安裝 JRebel Eclipse插件進入 Help » Install New Software... 並且輸入下面的URL :
http://www.zeroturnaround.com/update-site/

離線安裝包下載地址:
http://www.zeroturnaround.com/update-site/update-site.zip




如果你不選擇嵌入JRebel,你需要手動填上jrebel.jar的系統中實際路徑. 進入 Window » Preferences » JRebel a看到下面的圖然後輸入jrebel.jar的路徑




需要設置調試可以進入 Window » Preferences 然後到 Java » Debug » Step Filtering.

選中 Use Step FiltersFilter synthetic methods及Step through filters. 現在選中所有的默認filters,然後點擊Add Filter按鈕,添加com.zeroturnaround.* 和 org.zeroturnaround.*.



進入 Project » Build Automatically 確認以被選中.




Eclipse Tomcat設置

2.2 Eclipse

Tomcat server配置中的不需要自動發佈. 雙擊服務器名稱打開服務器配置頁面選中Never publish automatically 和(Enable JRebel agent) .



如果你運行一個獨立的應用服務器你可以選擇enable JRebel agent.




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章