簡單eclipse插件開發: eclipse啓動時間顯示器

Eclipse插件開發shell

1. 下載並安裝jdk和eclipse
   這裏強調一下: 須要下載Eclipse for RCP and RAP Developers, 不然沒法新建Plug-in Development 項目.
2. 新建項目
   安裝好以後打開eclipse, 點擊 File->NewProject。選擇Plug-in Project,點擊Next。新建一個名爲com.developer.showtime的項目,全部參數採用默認值.eclipse

3. 在com.developer.showtime項目的src下新建一個類: ShowTime,代碼以下:ui

  

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文件以下:orm

 

<?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>xml

5. 試運行ip

右鍵點擊Run as -> Eclipse Application. 此時會運行一個eclipse, 啓動以後就能顯示啓動所需時間.開發

6. 導出插件.get

右鍵Export -> Deployable plug-ins and fragments. 在Directory中輸入須要導出的路徑, 點擊finish後會在該目錄下產生一個plugins的目錄, 裏面就是插件包: com.developer.showTime_1.0.0.201110161216.jar. 把這個包複製到eclipse目錄下的plugin目錄下. 而後再啓動eclipse 即可以看到eclipse啓動所花的時間.io

相關文章
相關標籤/搜索