有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

检测到java Eclipse插件,但未加载

我正在编写一个插件,它使用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");
    }
}

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

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

在我的插件中。xml我指定:

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

我将插件导出到一个归档文件中,并将内容放在dropins文件夹中。当我启动Eclipse时,我会看到安装细节>;配置:
myplugin (1.0.0) "My Plugin" [Installed]

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


共 (1) 个答案

  1. # 1 楼答案

    重读这个问题,我觉得以下几点不一致:

    • 不应该手动实例化激活器,但框架应该为您这样做
    • 对于框架的实例化,激活器需要一个公共无arg构造函数。
      • 为了支持单例访问,激活器通常从构造函数或start()方法中保存this
    • 为了让类加载触发bundle激活,bundle应该声明Bundle-ActivationPolicy: lazy

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