【问题标题】:Eclipse plugin detected but not loaded检测到 Eclipse 插件但未加载
【发布时间】:2018-08-20 08:44:45
【问题描述】:

我正在编写一个使用 JDT 的 compilationParticipant 扩展点的插件。该插件现在无法正常工作,我试图找出原因。

我有一个CompilationParticipant

public class CompParticipant extends CompilationParticipant {

    private static CompParticipant instance = null;    
    private CompParticipant() {
        super();
        Activator.log("CompilationParticipant initialized");
    }

   public CompParticipant getSingleton() {
        if (instance == null)
            instance = new CompParticipant();
        return instance;
    }

    @Override
    public void buildStarting(BuildContext[] files, boolean isBatch) {
        Activator.log("Build Starting");
    }
}

还有一个(不是懒惰的)Activator

public class Activator extends Plugin implements BundleActivator {

    private static Activator instance;
    public static String PLUGINID = "myplugin";

    public Activator() {
        super();
        log("Activator");
    }

    public static void log(String msg) {        
        if (instance == null)
            instance = new Activator();
        instance.getLog().log(new Status(Status.WARNING, PLUGINID, 1, msg, null));
    }

    @Override
    public void start(BundleContext context) throws Exception { log("Start"); }

    @Override
    public void stop(BundleContext context) throws Exception {}

}

在我的清单中我指定:

Bundle-Activator: myplugin.Activator

在我的 plugin.xml 中我指定:

<extension point="org.eclipse.jdt.core.compilationParticipant">
  <compilationParticipant class="myplugin.CompParticipant" id="myplugin" createsProblems="true">
  </compilationParticipant>
</extension>

我将插件导出到存档并将内容放在dropins 文件夹中。当我启动 Eclipse 时,我在 Installation Details > Configuration 部分看到 *** Plug-in Registry:
myplugin (1.0.0) "My Plugin" [Installed]

但是,没有日志消息会打印到错误日志(或控制台中)。我的日志记录不正确还是为什么我的插件没有运行?

【问题讨论】:

    标签: java eclipse-plugin eclipse-jdt


    【解决方案1】:

    重新阅读问题,以下内容对我来说似乎不一致:

    • 不应手动实例化激活器,但框架应为您执行此操作。
    • 对于框架的实例化,激活器需要一个 public 无参数构造函数。
      • 为了支持单例访问,激活器通常会在构造函数或 start() 方法中保存 this
    • 要让类加载触发捆绑激活,捆绑应该声明Bundle-ActivationPolicy: lazy

    当所有这些都得到纠正后,构建器应该能够实例化您的 CompilationParticipant(从扩展声明中读取)。这个实例化应该会激活你的包并启动激活器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      • 2015-10-06
      • 2023-03-30
      • 1970-01-01
      • 2011-08-02
      相关资源
      最近更新 更多