1、新建Plug-in Project
不用改其他選項,直接點擊“Next”,然后點擊“Finish”
2、新建ShowTime.java
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{ @Override public void earlyStartup() { Display.getDefault().syncExec(new Runnable(){ @Override public void run() { long eclipseStartTime = Long.parseLong(System.getProperty("eclipse.startTime")); long costTime = System.currentTimeMillis() - eclipseStartTime; Shell shell = Display.getDefault().getActiveShell(); String message = "eclipse 啟動時間:" + costTime + "ms"; MessageDialog.openInformation(shell, "Information", message); } }); } }
3、新建plugin.xml
右鍵項目,點擊New File,輸入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>
4、修改MANIFEST.MF
將其中的Bundle-SymbolicName改為:
“Bundle-SymbolicName: com.developer.showtime;singleton:=true”
5、試運行
右鍵項目-> Run as -> Eclipse Application

6、導出成jar包
右鍵項目-> export->Deployable plug-ins and fragments


選擇Directory,這里需要注意的是,要選擇eclipse目錄,不用選擇plugins目錄,因為會默認在$Directory/plugins下
7、重啟eclipse
可能出現的錯誤:
1、export時報中文亂碼:
解決方法:在build.properties中添加一行”javacDefaultEncoding.. = UTF-8"
2、打出的jar包內缺少plugin.xml
不知道為什么,我的包里沒有包括plugin.xml,這個問題困惑了我好久,偶然間打開jar包看了才知道。
解決方法:復制一下plugin.xml進jar包就好了
可供下載:http://pan.baidu.com/s/1kVOdkTh