【问题标题】:LinkageError in eclipse CDT plugin that using OSGI使用 OSGI 的 Eclipse CDT 插件中的 LinkageError
【发布时间】:2015-12-02 03:24:20
【问题描述】:

我正在 Windows 上编写 eclipse CDT 插件。 我想将代码写入项目中的现有文件,但我需要自动格式化代码。我用谷歌搜索和搜索,找到了这个解决方案:

CodeFormatter formatter = ToolFactory.createDefaultCodeFormatter(null);
TextEdit formatEdit = formatter.format(CodeFormatter.K_UNKNOWN, source, 0, source.length(), 0, null);
IDocument dc = new Document(source);
formatEdit.copy();
formatEdit.apply(dc);
System.out.println(dc.get());

为了让这段代码正常工作(至少部分),我添加了以下导入:

import org.eclipse.cdt.core.ToolFactory;
import org.eclipse.cdt.core.formatter.CodeFormatter;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.text.edits.TextEdit;

以及类路径和 plugin.xml 运行时定义中的以下库:

<classpathentry kind="lib" path="libs/org.eclipse.cdt.core_5.6.0.201402142303.jar"/>
<classpathentry kind="lib" path="libs/org.eclipse.osgi_3.9.1.v20140110-1610.jar"/>
<classpathentry kind="lib" path="libs/org.eclipse.osgi.services_3.3.100.v20130513-1956.jar"/>
<classpathentry kind="lib" path="libs/org.eclipse.osgi.services.source_3.3.100.v20130513-1956.jar"/>
<classpathentry kind="lib" path="libs/org.eclipse.osgi.source_3.9.1.v20140110-1610.jar"/>
<classpathentry kind="lib" path="libs/org.eclipse.osgi.util_3.2.300.v20130513-1956.jar"/>
<classpathentry kind="lib" path="libs/org.eclipse.osgi.util.source_3.2.300.v20130513-1956.jar"/>
<classpathentry kind="lib" path="libs/org.eclipse.text_3.5.300.v20130515-1451.jar"/>

我确信有这么多依赖项,代码可以工作 - 但现在我正在调试,并在运行时收到以下异常:

java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) previously initiated loading for a different type with name "org/eclipse/text/edits/TextEdit"

我看到这个话题已经讨论过了,但我自己 - 没有找到解决方案。

谁能帮帮我?

【问题讨论】:

  • 大多数 Eclipse 插件将仅作为 Eclipse RCP 的一部分运行,因为它们依赖于 RCP 启动时完成的大量初始化。
  • 谢谢,但我不明白如果这是现实我能做什么?
  • 对不起,我想我可能误读了这个问题。如果这是一个 Eclipse 插件,你应该能够让它工作。您是否在 MANIFEST.MF 编辑器中将所有这些插件添加为依赖项?仅将内容添加到类路径对于插件来说是不正确的。
  • 是的,我将它们添加到 MANIFEST.MF 和运行时 classPath :(
  • 您不应该将插件添加到运行时类路径中,应该只添加一个 Eclipse 将添加的条目 &lt;classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/&gt;

标签: eclipse-plugin osgi classloader eclipse-cdt linkageerror


【解决方案1】:

我找到了解决方案。正如@greg-449 回答的那样,我必须将想要的 jar 添加到 MANIFEST.MF 中的依赖项中。 谢谢!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-31
    • 2019-11-17
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 2016-05-15
    • 2010-09-18
    • 2011-11-08
    相关资源
    最近更新 更多