我正在编写一个eclipse插件,项目环境配置正确(我相信)。
我能够编译解决方案而没有任何编译时错误。以下是在调试解决方案时抛出异常的代码片段。我确信所有必需的插件和外部罐都配置正确。
我已尝试过几乎所有用户在互联网上建议的方法,但没有任何效果。 (我甚至根据他们的建议改变了代码)。
所以请你告诉我为什么我会低于错误并建议替代方法。
public static IProject getCurrentSelectedProject() {
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject[] projects = workspace.getRoot().getProjects();
for (int i = 0; i < projects.length; i++) {
IProject project = projects[i];
if ((project.isOpen())) {
return project;
}
}
} catch (Throwable ex) {
ex.printStackTrace();
}
return null;
}
以下是我收到的错误
java.lang.NoClassDefFoundError: org/eclipse/core/resources/ResourcesPlugin
at com.prithvi.editor.actions.UploadAction.getCurrentSelectedProject(UploadAction.java:81)
at com.prithvi.editor.actions.UploadAction.run(UploadAction.java:39)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:229)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1029)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
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:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
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:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.resources.ResourcesPlugin
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 33 more
答案 0 :(得分:7)
- &gt;打开Plugin.xml
- &gt;依赖选项卡
- &gt;点击添加 - &gt; org.eclipse.core.resources
答案 1 :(得分:4)
启动应用程序时,您必须在启动配置中指定应加载哪些插件(与您自己的插件一起),或者如果您有产品配置,则只需在该产品配置中包含的插件和功能启动。
通常情况下工作得很好,因为Eclipse识别不同插件之间的依赖关系,因此会自动添加所有必需的插件。但是,org.eclipse.core.resources是一个小例外,您必须手动添加这3个中的一个: