1. 程式人生 > >eclipse plugin啟動順序

eclipse plugin啟動順序

依賴關係

兩個plugin test1和test2;
1. test1和test2沒有依賴關係
因為沒有顯式說明是early start,所以使用lazy start,只有在真正使用到時,才會呼叫具體的建構函式和start方法;
test1 contructor
test1 start
test2 contructor
test2 start

2. test2依賴於test1
這個依賴分三種:
2.1 如果只是在test2的MANIFEST.MF檔案中的Require-Bundle中出現;
這時兩個是沒有關係的;

2.2 如果在test2中的java檔案中出現import test1中的包:
這時兩個還是沒有關係的;

2.3 在test2中使用到了test1中的類:
在使用的地方才會初始化test1;例如在test2的建構函式處使用test1中的類:
test2 contructor
test1 contructor
test1 start
test2 start

3. 相互依賴
如果出現相互依賴,執行程式的時候,會提示有錯誤,但是如果不管錯誤提示,繼續執行的話,還是可以啟動;
但是最好還是將相互依賴打破,因為這樣不符合設計規範。

4. early starup

一般不推薦使用early startup,因為eclipse設計時就是為了快速啟動,才將顯示(plugin.xml)和實現(*.java,*.icon, etc)分離的。
使用early startup,需要在plugin.xml檔案中追加一個extension org.eclipse.ui.startup,同事實現IStartup介面。

這樣eclipse就會使用單獨的程序啟動該plugin。
如果有依賴的plugin,它同時將依賴的plugin初始化;
需要注意的是:如果沒有實現IStartup,eclipse會報錯,但是也會將plugin在單獨的程序中啟動。
實現了IStartup:
test2 contructor
test1 contructor
test1 start
test2 start
test2 early startup

沒有實現IStartup:
test2 contructor
test1 contructor
test1 start
test2 start

!ENTRY org.eclipse.ui 4 4 2011-06-17 10:58:47.328
!MESSAGE Bad extension specification

!ENTRY test2 4 0 2011-06-17 10:58:47.359
!MESSAGE startup class must implement org.eclipse.ui.IStartup

refs: