Eclipse-PDE:扩展AbstractDecoratedTextEditor时有趣的IDE行为

时间:2014-05-25 14:07:42

标签: eclipse eclipse-plugin eclipse-pde

我正在使用Kepler SR2编写Eclipse插件。假设我创建了一个空白插件plugin1,并添加以下虚拟类:

package com.example.plugin1;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;

public class MyEditor extends AbstractDecoratedTextEditor {

    public static void main(String[] args) {
        System.out.println(MyEditor.class);
    }
}

IDE没有给我自然的修复提示(添加org.eclipse.ui.editors),我手动将其添加到依赖项(“必需的插件”)。然后有趣的事情开始发生。 该类仍被标记为有错误,并出现以下隐藏错误:

  

类型org.eclipse.jface.text.revisions.RevisionInformation不能   得到解决。它是从所需的.class文件间接引用的

我不确定这意味着什么,所以我尝试将org.eclipse.jface.text添加到所需的插件中。然后它编译没有错误。但是当我尝试从Eclipse启动器执行我的(非常愚蠢但合法的)类时,以及来自Launcher的一个奇怪的弹出窗口:“发生了Java异常”,并且控制台吐出了这个堆栈跟踪:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/ui/actions/WorkspaceModifyOperation
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.eclipse.ui.actions.WorkspaceModifyOperation
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 6 more

我还尝试使用Class.forName(在另一个类中)

在运行时加载该类
public static void main(String[] args) throws ClassNotFoundException {
    System.out.println("trying...");
    Class c=Class.forName("com.example.plugin1.MyEditor");
    System.out.println("class=" + c);
}

并在加载课程时再次失败。如果我在调试模式下启动它,我可以检查Eclipse启动器似乎正确计算类路径:这是我的转储:

\eclipse\plugins\org.eclipse.ui_3.105.0.v20130522-1122.jar
\eclipse\plugins\org.eclipse.swt_3.102.1.v20140206-1334.jar
\eclipse\plugins\org.eclipse.swt.win32.win32.x86_3.102.1.v20140206-1358.jar
\eclipse\plugins\org.eclipse.jface_3.9.1.v20130725-1141.jar
\eclipse\plugins\org.eclipse.core.commands_3.6.100.v20130515-1857.jar
\eclipse\plugins\org.eclipse.ui.workbench_3.105.2.v20140211-1711.jar
\eclipse\plugins\org.eclipse.e4.ui.workbench3_0.12.0.v20130515-1857.jar
\eclipse\plugins\org.eclipse.core.runtime_3.9.100.v20131218-1515.jar
\eclipse\plugins\javax.annotation_1.1.0.v201209060031.jar
\eclipse\plugins\javax.inject_1.0.0.v20091030.jar
\eclipse\plugins\org.eclipse.osgi_3.9.1.v20140110-1610.jar
\eclipse\plugins\org.eclipse.equinox.common_3.6.200.v20130402-1505.jar
\eclipse\plugins\org.eclipse.core.jobs_3.5.300.v20130429-1813.jar
\eclipse\plugins\org.eclipse.core.runtime.compatibility.registry_3.5.200.v20130514-1256\runtime_registry_compatibility.jar
\eclipse\plugins\org.eclipse.equinox.registry_3.5.301.v20130717-1549.jar
\eclipse\plugins\org.eclipse.equinox.preferences_3.5.100.v20130422-1538.jar
\eclipse\plugins\org.eclipse.core.contenttype_3.4.200.v20130326-1255.jar
\eclipse\plugins\org.eclipse.equinox.app_1.3.100.v20130327-1442.jar
\eclipse\plugins\org.eclipse.ui.editors_3.8.100.v20130513-1637.jar
\eclipse\plugins\org.eclipse.core.filebuffers_3.5.300.v20130225-1821.jar
\eclipse\plugins\org.eclipse.jface.text_3.8.101.v20130802-1147.jar
\eclipse\plugins\org.eclipse.text_3.5.300.v20130515-1451.jar
\eclipse\plugins\org.eclipse.ui.ide_3.9.2.v20131004-0923.jar
\eclipse\plugins\org.eclipse.ui.views_3.6.100.v20130326-1250.jar
\eclipse\plugins\org.eclipse.ui.workbench.texteditor_3.8.101.v20130729-1318.jar

我无法理解这一点。为什么我不能加载课程?有什么想法吗?

1 个答案:

答案 0 :(得分:0)

好吧,我通过添加更多插件来修复它。除了org.eclipse.ui.editors之外,所需的全套插件似乎是:

org.eclipse.jface.text
org.eclipse.ui
org.eclipse.core.resources
org.eclipse.core.filesystem

这些仅仅是经验性的。我想知道为什么我必须手动添加这些,不应该是org.eclipse.ui.editors所需的依赖项吗?...