首先申明下,本文为笔者学习《Eclipse插件开发学习笔记》的笔记,并加入笔者自己的理解和归纳总结。
创建Plug-in项目
在Eclipse里,依次选择【File】->【New】->【Project】,选择【Plug-in Project】选项。
在配置里面选择生成【Activator】类用来控制插件的生命周期。
Activator
类被默认实现,继承AbstractUIPlugin
。其中start()
和stop()
方法,分别会在启动和停止时调用。
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "com.plugin.blog.demo"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
如果找不到SWT源码,或者扩张点时出错,可以下载Eclipse SDK