【问题标题】:start method of Activator of Eclipse Plugin is not calledEclipse Plugin的Activator的start方法没有被调用
【发布时间】:2016-05-15 04:28:55
【问题描述】:

我正在制作一个插件来在 Eclipse 4.x 中提供 Preference Page。

我在 Vogella-Preferences 上关注了本教程。

页面的问题是,在我输入一次值,然后退出,然后重新打开首选项后,值没有保留。可能的原因可能是未指定 PreferenceStore。

以下是偏好页面的代码:

import com.varun.preference.main.Activator;

public class EASEPreferences extends FieldEditorPreferencePage 
                implements IWorkbenchPreferencePage {

    public EASEPreferences(){
        super(GRID);
    }

    @Override
    public void init(IWorkbench workbench) {

        setPreferenceStore(getPreferenceStore());
//      setPreferenceStore(Activator.getDefault().getPreferenceStore());
        setDescription("Final Implementation");
    }

    @Override
    protected void createFieldEditors() {

        addField(new DirectoryFieldEditor("PATH", "Get &Default Keystore:",
                getFieldEditorParent()));

        addField(new BooleanFieldEditor("BOOLEAN_VALUE",
            "&Automatically run scripts that are not signed(Not Recommended)", 
            getFieldEditorParent()));
    }
}

现在,代码正在运行,偏好页面可见,但未保存。

如果我取消注释第二行 init 方法并先注释,则错误提示

java.lang.NullPointerException 在 com.varun.preference.page_final.EASEPreferences.init(EASEPreferences.java:24)

Activator.java 如下

public class Activator extends AbstractUIPlugin {

    public static Activator plugin;
    public static BundleContext context;

    public Activator() {
    }

    @Override
    public void start(BundleContext context){

        Activator.context = context;
        System.out.println("---InStart---");
        plugin = this;
    }

    @Override
    public void stop(BundleContext context){

        Activator.context = null;
    }

    public static Activator getDefault(){

        return plugin;
    }

}

在这里,我假设 start 方法在运行插件时没有被调用,因为 println 语句没有被打印出来。

我是否缺少 Activator 的某些内容?

我的 Manifest.mf 文件是:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Final
Bundle-SymbolicName: com.varun.preference.page.final;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: VARUN
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime
Bundle-Activator: com.varun.preference.main.Activator

我没有使用任何产品或功能。这是一个简单的插件。

Eclipse 版本:4.5.2

谢谢。

【问题讨论】:

    标签: eclipse eclipse-plugin eclipse-rcp


    【解决方案1】:

    你的问题是你没有检查:当它的一个类被加载时激活这个插件MANIFEST.MF配置中。检查添加:

    Bundle-ActivationPolicy: lazy
    

    发送至您的MANIFEST.MF,然后一切正常。

    当您拥有Bundle-ActivationPolicy: lazy 时,这意味着您不必显式启动您的包,这是一件好事。在 Eclipse 中,您希望尽可能地懒惰地做事,而启动一个包就是一个很好的例子。

    阅读有关tracking lifecylesstarting them 的更多信息。

    【讨论】:

    • 另外,如果选中此标志,请确保从插件加载某些类,否则在停止该插件(Eclipse 氧气)时可能会出现捆绑异常(未初始化)
    • 另外,如果在产品配置(配置 - 选项卡)中,如果启用了自动启动并且仍然没有加载类,则在停止插件或 rcp 应用程序时会出现异常。为了更正,重新检查并取消选中延迟启动(如果没有使用插件中的类)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 2013-12-02
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多