eclipse插件依赖项和classnotfoundexception

时间:2023-01-15 12:45:48

I am new to Eclipse RCP plugin development and I have the following problem: I am trying to instantiate a MessageConsole object in my plugin. I create the appropriate dependency for org.eclipse.ui.console in MANIFEST.MF, build the plugin, and then load the plugin inside the same Eclipse application (I export the plugin as a zip, shutdown Eclipse, unzip and copy the plugin into Eclipse's plugin directory, restart Eclipse). I get a NoClassDefFoundError when that plugin is loaded. If I uncomment the single source code line (see below) that tries to instantiate a MessageConsole, the plugin works fine. Details are as follows.

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

MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: IntrospectorPlugin Plug-in
Bundle-SymbolicName: IntrospectorPlugin; singleton:=true
Bundle-Version: 1.0.1
Bundle-Activator: introspectorplugin.Activator
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 org.eclipse.ui.console
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6

IntrospectorView.java:

import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleConstants;
import org.eclipse.ui.console.IConsoleView;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
...
     MessageConsole myConsole = new MessageConsole("IntrospectorView plugin console",
        imageDescriptorConsole);

Exception:

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

I looked through my Plugins book which talks about making sure that compile-time dependencies much target run-time dependencies -- if I run the plugin in the same Eclipse executable that I build, I should not have this issue? Furthermore, I've descended down the plug-in dependencies tree and verified I have all necessary plugins.

我查看了我的插件书,其中讨论了确保编译时依赖项更多地针对运行时依赖项 - 如果我在我构建的相同Eclipse可执行文件中运行插件,我不应该有这个问题吗?此外,我已经下载了插件依赖树,并验证了我有所有必要的插件。

All help is appreciated, thanks!

感谢所有帮助,谢谢!

2 个解决方案

#1


I installed a newer version of Eclipse today, added my plugin into the plugins directory and everything works well. Obviously I've encountered some configuration issue or a quirk. My previous version was Ganymede and now I'm running Galileo.

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

#2


You could try and compare your implementation with other example and projects including a Console view, like:

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

In both case, check their dependencies (plugin.xml or the MANIFEST.MF) in order to see what the difference is, hopefully explaining why your plugin does not include the relevant classes.

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

#1


I installed a newer version of Eclipse today, added my plugin into the plugins directory and everything works well. Obviously I've encountered some configuration issue or a quirk. My previous version was Ganymede and now I'm running Galileo.

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

#2


You could try and compare your implementation with other example and projects including a Console view, like:

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

In both case, check their dependencies (plugin.xml or the MANIFEST.MF) in order to see what the difference is, hopefully explaining why your plugin does not include the relevant classes.

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