2

我是 Eclipse RCP 插件开发的新手,我遇到以下问题:我正在尝试在我的插件中实例化 MessageConsole 对象。我在 MANIFEST.MF 中为 org.eclipse.ui.console 创建适当的依赖项,构建插件,然后在同一个 Eclipse 应用程序中加载插件(我将插件导出为 zip,关闭 Eclipse,解压缩并将插件复制到Eclipse的插件目录,重启Eclipse)。加载该插件时出现 NoClassDefFoundError 。如果我取消注释尝试实例化 MessageConsole 的单个源代码行(见下文),则该插件可以正常工作。详情如下。

清单.MF:

清单版本:1.0
捆绑清单版本:2
Bundle-Name: IntrospectorPlugin 插件
Bundle-SymbolicName:IntrospectorPlugin;单例:=真
捆绑版本:1.0.1
Bundle-Activator:introspectorplugin.Activator
要求捆绑:org.eclipse.ui,
 org.eclipse.core.runtime,
 org.eclipse.ui.console
Bundle-ActivationPolicy:懒惰
Bundle-RequiredExecutionEnvironment:JavaSE-1.6

IntrospectorView.java:

导入 org.eclipse.ui.console.ConsolePlugin;
导入 org.eclipse.ui.console.IConsole;
导入 org.eclipse.ui.console.IConsoleConstants;
导入 org.eclipse.ui.console.IConsoleView;
导入 org.eclipse.ui.console.MessageConsole;
导入 org.eclipse.ui.console.MessageConsoleStream;
...
     MessageConsole myConsole = new MessageConsole("IntrospectorView 插件控制台",
        图像描述符控制台);

例外:

java.lang.ClassNotFoundException:org.eclipse.ui.console.MessageConsole
    在 org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:483)
    在 org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
    在 org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
    在 org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
    在 java.lang.ClassLoader.loadClass(未知来源)
    在 java.lang.ClassLoader.loadClassInternal(未知来源)
    在 introspectorplugin.views.IntrospectorView.makeConsole(IntrospectorView.java:453)
    在 introspectorplugin.views.IntrospectorView.createPartControl(IntrospectorView.java:436)
    在 org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:371)
    在 org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:230)
    在 org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:594)
    在 org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:306)
    在 org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:531)
    在 org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
    在 org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
    在 org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
    在 org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
    在 org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1256)
    在 org.eclipse.ui.internal.PartStack.createControl(PartStack.java:668)
    在 org.eclipse.ui.internal.PartStack.createControl(PartStack.java:576)
    在 org.eclipse.ui.internal.PartSashContainer.createControl(PartSashContainer.java:568)
    在 org.eclipse.ui.internal.PerspectiveHelper.activate(PerspectiveHelper.java:271)
    在 org.eclipse.ui.internal.Perspective.onActivate(Perspective.java:968)
    在 org.eclipse.ui.internal.WorkbenchPage.onActivate(WorkbenchPage.java:2593)
    在 org.eclipse.ui.internal.WorkbenchWindow$25.run(WorkbenchWindow.java:2873)
    在 org.eclipse.swt.custom.BusyIndi​​cator.showWhile(BusyIndi​​cator.java:70)
    在 org.eclipse.ui.internal.WorkbenchWindow.setActivePage(WorkbenchWindow.java:2854)
    在 org.eclipse.ui.internal.WorkbenchWindow$19.runWithException(WorkbenchWindow.java:2171)
    在 org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
    在 org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    在 org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:133)
    在 org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3800)
    在 org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3425)
    在 org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
    在 org.eclipse.ui.internal.Workbench$27.runWithException(Workbench.java:1363)
    在 org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
    在 org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    在 org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:133)
    在 org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3800)
    在 org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3425)
    在 org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2295)
    在 org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2200)
    在 org.eclipse.ui.internal.Workbench$5.run(Workbench.java:495)
    在 org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
    在 org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:490)
    在 org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    在 org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
    在 org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
    在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
    在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    在 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)
    在 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)
    在 java.lang.reflect.Method.invoke(未知来源)
    在 org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
    在 org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
    在 org.eclipse.equinox.launcher.Main.run(Main.java:1236)

我浏览了我的插件书,该书谈到确保编译时依赖项主要针对运行时依赖项——如果我在我构建的同一个 Eclipse 可执行文件中运行插件,我不应该有这个问题吗?此外,我已经沿着插件依赖关系树向下,并验证我拥有所有必要的插件。

感谢所有帮助,谢谢!

4

2 回答 2

1

我今天安装了更新版本的 Eclipse,将我的插件添加到插件目录中,一切正常。显然我遇到了一些配置问题或怪癖。我以前的版本是 Ganymede,现在我正在运行 Galileo。

于 2009-07-29T21:23:06.250 回答
0

您可以尝试将您的实现与其他示例和项目(包括控制台视图)进行比较,例如:

在这两种情况下,检查它们的依赖项(plugin.xmlMANIFEST.MF)以查看有什么区别,希望能解释为什么您的插件不包含相关类。

于 2009-07-28T04:13:57.983 回答