Eclipse版本如下:
Eclipse Java EE IDE for Web Developers.
Version: Kepler Service Release 2
Build id: 20140224-0627
File->New->Plug-in Project
Project name填com.developer.showtime,Eclipse version是3.5以后
Options不要生成activator,其他都是默認(rèn)
不要Create a plug-in using one of the template,直接創(chuàng)建空的即可
然后新建一個(gè)ShowTime類,實(shí)現(xiàn)IStartup接口,這里需要import三個(gè)eclipse包,org.eclipse.jface、swt、ui,在eclipse/plugins/目錄下可以找到org.eclipse相關(guān)的jar包,添加到build path中。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{
@Override
public void earlyStartup() {
// TODO Auto-generated method stub
Display. getDefault().syncExec(new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
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);
}
});
}
}
創(chuàng)建plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.5"?>
<plugin>
<extension point= "org.eclipse.ui.startup">
<startup class= "com.developer.showtime.ShowTime" />
</extension>
</plugin>
修改MANIFEST.MF文件:
Manifest-Version: 1.0
Bundle-ManifestVersion : 2
Bundle-Name: Showtime
Bundle-SymbolicName : com.developer.showtime;singleton:=true
Bundle-Version : 1.0.0.qualifier
Bundle-Vendor : DEVELOPER
Require-Bundle : org.eclipse.ui,org.eclipse.jface,org.eclipse.swt
Bundle-RequiredExecutionEnvironment : JavaSE-1.7
注意這里要添加Require-Bundle,否則插件運(yùn)行時(shí)找不到org.eclipse包。
現(xiàn)在就可以Run as -> Eclipse Application運(yùn)行了,這時(shí)會(huì)啟動(dòng)一個(gè)新的eclipse并運(yùn)行該插件,成功后就可以導(dǎo)出插件了。
Export->Deployable plug-ins and fragments,將com.developer.showtime_1.0.0.xxxxxxx.jar復(fù)制到eclipse/plugins/目錄下,重新啟動(dòng)eclipse即可(本人的測(cè)試,這一步暫時(shí)沒成功。。。)。