Eclipse启动计时插件

 
Eclipse版本如下:
Eclipse Java EE IDE for Web Developers.

Version: Kepler Service Release 2
Build id: 20140224-0627

不需要下载额外的 Eclipse for RCP and RAP Developers

File->New->Plug-in Project
Project name填com.developer.showtime,Eclipse version是3.5以后
Options不要生成activator,其他都是默认
不要Create a plug-in using one of the template,直接创建空的即可

然后新建一个ShowTime类,实现IStartup接口,这里需要import三个eclipse包,org.eclipse.jface、swt、ui,在eclipse/plugins/目录下可以找到org.eclipse相关的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);
                  }
                  
            });
      }
      
}

创建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,否则插件运行时找不到org.eclipse包。

现在就可以Run as -> Eclipse Application运行了,这时会启动一个新的eclipse并运行该插件,成功后就可以导出插件了。
Eclipse启动计时插件_第1张图片

Export->Deployable plug-ins and fragments,将com.developer.showtime_1.0.0.xxxxxxx.jar复制 到eclipse/plugins/目录下,重新启动eclipse即可(本人的测试,这一步暂时没成功。。。)。

你可能感兴趣的:(java,eclipse,插件,启动计时)