简体   繁体   English

Eclipse插件外部的Eclipse工作区参考

[英]Eclipse workspace reference outside eclipse plugin

I'm running the following code: 我正在运行以下代码:

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;

public class WorkspaceTest {
    public static void main(String[] args) {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
    }
}

and I get the following error: 我收到以下错误:

Exception in thread "main" java.lang.IllegalStateException: Workspace is closed.

How can I get a reference to the workspace for a non-eclipse plugin? 如何获取非蚀插件的工作空间引用?

(To be able to run the code here:) (为了能够在此处运行代码:)

http://www.ssw.uni-linz.ac.at/Teaching/Lectures/KompTech/JDT.pdf http://www.ssw.uni-linz.ac.at/Teaching/Lectures/KompTech/JDT.pdf

First, it can simply means you are not running under Eclipse but instead under just a standard Java application. 首先,它仅表示您不是在Eclipse下运行,而是在标准Java应用程序下运行。

For an eclipse plugin, you need did to not call it too soon (like before creating workspace). 对于eclipse插件,您无需太早调用它(例如在创建工作区之前)。 Meaning for a non-eclipse plugin, you may have to somehow create a workspace, since you would not be able to reference the ones already present in eclipse. 对于非eclipse插件的含义,您可能必须以某种方式创建一个工作区,因为您将无法引用eclipse中已经存在的插件。

Plus, you have to make sure you do not have org.eclipse.core.resources in the build path but rather as a dependent plugin in the plugin manifest.mf file. 另外,您必须确保在构建路径中没有org.eclipse.core.resources ,而是在manifest.mf文件中将其作为从属插件。 (see this thread ) (请参阅此线程
So the ResourcePlugin was not being instantiated by eclipse (although you could still have made calls to the ResourcePlugin class with the code). 因此,Eclipse不会实例化ResourcePlugin (尽管您仍然可以使用代码对ResourcePlugin类进行调用)。

See also this answer for other ideas. 另请参见此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM