Eclipse启动计时器插件开发

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

猜你喜欢

转载自blog.csdn.net/u013278314/article/details/79771591