Posted on 2011-10-16 13:07
俞靈 閱讀(7114)
評(píng)論(2) 編輯 收藏
Eclipse插件開發(fā)
1. 下載并安裝jdk和eclipse
這里強(qiáng)調(diào)一下: 需要下載Eclipse for RCP and RAP Developers, 否則無法新建Plug-in Development 項(xiàng)目.
2. 新建項(xiàng)目
安裝好之后打開eclipse, 點(diǎn)擊 File->NewProject。選擇Plug-in Project,點(diǎn)擊Next。新建一個(gè)名為com.developer.showtime的項(xiàng)目,所有參數(shù)采用默認(rèn)值.
3. 在com.developer.showtime項(xiàng)目的src下新建一個(gè)類: ShowTime,代碼如下:
package com.developer.showtime;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IStartup;
public class ShowTime implements IStartup {
public void earlyStartup() {
Display.getDefault().syncExec(new Runnable() {
public void run(){
long eclipseStartTime = Long.parseLong(System.getProperty("eclipse.startTime"));
long costTime = System.currentTimeMillis() - eclipseStartTime;
Shell shell = Display.getDefault().getActiveShell();
String message = "Eclipse start in " + costTime + "ms";
MessageDialog.openInformation(shell, "Information", message);
}
});
}
}
4. 修改plugin.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.startup">
<startup class="com.developer.showtime.ShowTime"/>
</extension>
</plugin>
5. 試運(yùn)行
右鍵點(diǎn)擊Run as -> Eclipse Application. 此時(shí)會(huì)運(yùn)行一個(gè)eclipse, 啟動(dòng)之后就能顯示啟動(dòng)所需時(shí)間.
6. 導(dǎo)出插件.
右鍵Export -> Deployable plug-ins and fragments. 在Directory中輸入需要導(dǎo)出的路徑, 點(diǎn)擊finish后會(huì)在該目錄下產(chǎn)生一個(gè)plugins的目錄, 里面就是插件包: com.developer.showTime_1.0.0.201110161216.jar. 把這個(gè)包復(fù)制到eclipse目錄下的plugin目錄下. 然后再啟動(dòng)eclipse 便可以看到eclipse啟動(dòng)所花的時(shí)間.