Eclipse插件开发
1. 下载并安装jdk和eclipse
这里强调一下: 需要下载Eclipse for RCP and RAP Developers, 否则无法新建Plug-in Development 项目.
2. 新建项目
安装好之后打开eclipse, 点击 File->NewProject。选择Plug-in Project,点击Next。新建一个名为com.developer.showtime的项目,所有参数采用默认值.
3. 在com.developer.showtime项目的src下新建一个类: 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);
}
});
}
}
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 >
<? eclipse version = " 3.4 " ?>
< plugin >
< extension
point = " org.eclipse.ui.startup " >
< startup class = " com.developer.showtime.ShowTime " />
</ extension >
</ plugin >
5. 试运行
右键点击Run as -> Eclipse Application. 此时会运行一个eclipse, 启动之后就能显示启动所需时间.
6. 导出插件.
右键Export -> Deployable plug-ins and fragments. 在Directory中输入需要导出的路径, 点击finish后会在该目录下产生一个plugins的目录, 里面就是插件包: com.developer.showTime_1.0.0.201110161216.jar. 把这个包复制到eclipse目录下的plugin目录下. 然后再启动eclipse 便可以看到eclipse启动所花的时间.