Eclipse插件开发问题

Eclipse插件开发问题

本文介绍了Eclipse插件开发问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个eclipse插件,并且项目环境配置正确(我相信)。



我可以编译解决方案,没有任何编译时错误。在调试解决方案时抛出异常的代码段。我确定所有必需的插件和外部jar都配置正确。



我已经尝试了几乎用户在互联网上建议的方法,没有任何工作。 (我甚至根据他们的建议更改了代码)。



所以要求你让我知道我为什么会低于错误,并提出替代方法。 / p>

  public static IProject getCurrentSelectedProject(){
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject [] projects = workspace.getRoot()。getProjects(); (int i = 0; i< projects.length; i ++){
IProject project = projects [i];

if((project.isOpen())){
return project;
}
}
} catch(Throwable ex){
ex.printStackTrace();
}
返回null;

}

以下是我收到的错误

  java.lang.NoClassDefFoundError:org / eclipse / core / resources / ResourcesPlugin 
在com.prithvi.editor.actions.UploadAction.getCurrentSelectedProject (UploadAction.java:81)
在com.prithvi.editor.actions.UploadAction.run(UploadAction.java:39)
在org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java :251)
在org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:229)
在org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)$在$ org.eclipse.jface.action.ActionContributionItem $ 5.handleEvent(ActionContributionItem.java:411)
b在org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
在org.eclipse.swt.widgets.Widget.sendEvent(Wid get.java:1053)
在org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
在org.eclipse.swt.widgets.Display.readAndDispatch(Display.java: 3758)
在org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine $ 9.run(PartRenderingEngine.java:1029)
在org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
在org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
在org.eclipse.e4.ui.internal .workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
在org.eclipse.ui.internal.Workbench $ 5.run(Workbench.java:588)
在org.eclipse.core.databinding。 observable.Realm.runWithDefault(Realm.java:332)
在org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
在org.eclipse.ui.PlatformUI.createAndRunWorkbench( PlatformUI.java:149)
在org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java :124)
在org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
在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:353)
在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)
在org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
在org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
在org .eclipse.equinox.launcher.Main.run(Main.java:1438)
在org.eclipse.equinox.launcher.Main.main(Main.java:1414)
导致:java.lang.ClassNotFoundException:org.eclipse.core.resources.ResourcesPlugin
在org.eclipse。 osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
在org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
在org.eclipse。 osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
在org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
在java.lang。 ClassLoader.loadClass(未知来源)
... 33更多


解决方案

- >打开Plugin.xml
- >依赖选项卡
- >单击添加 - > org.eclipse.core.resources / p>

I am writing one eclipse plugin and project environment is configured correctly (I believe).

I am able to compile the solution without any compile time errors.Following is the code snippet which is throwing exceptions while debugging the solution. I am sure that all the required plugins and external jars are configured properly.

I have tried almost all approaches that users suggested on internet and nothing worked. (I even changed the code also as per their suggestions).

So requesting you to let me know the reason why I am getting below error and suggest the alternate approaches.

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;

    }

Below is the error I am receiving

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
解决方案

->Open Plugin.xml->Dependencies Tab->Click Add -> org.eclipse.core.resources

这篇关于Eclipse插件开发问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 20:54