gpt4 book ai didi

eclipse - 尝试通过ResourcesPlugin获取工作区时出现"Workspace is closed"异常

转载 作者:行者123 更新时间:2023-12-02 09:13:42 25 4
gpt4 key购买 nike

尝试通过 ResourcesPlugin 获取工作区时出现此错误:

java.lang.IllegalStateException: Workspace is closed.
at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:339)

生成此代码的代码是:

IWorkspace ws = ResourcesPlugin.getWorkspace();

您能帮忙解决这个问题吗?

最佳答案

您的 Manifest.MF 中的 Require-bundle 部分是否包含 org.eclipse.core.resources

您是否将测试作为插件启动? (不是作为“Java 应用程序”)

另请参阅this thread .

如“Resources and the file system”帮助页面中所述,

You can access the workspace from the resources plug-in class (defined in org.eclipse.core.resources).

When the resources plug-in is not running, the workspace exists solely in the file system and is viewed or manipulated by the user via standard file-based tools. Let's look at what a workspace looks like on disk as we explain the resources plug-in API.

<小时/>

来自this book :

The workspace directory, regardless of the name defined with the -data invocation option, has two roles:

  • it acts as the parent for the .metadata directory
  • and as the default location for projects

the workspace can contains projects only when:

  • the org.eclipse.core.resources plugin is included in the configuration and
  • and appropriately started from the workbench

this is automatic from an IDE configuration based on the org.eclipse.ui.ide.workbench application.

另请参阅this thread并记住:

the workspace is a different workspace from the runtime-workspace that's used for testing plugins. When you do Run on an Eclipse PDE environment, it creates a new workspace which is completely empty.

测试workspace root can be specified through the "-data"启动选项。

If you want to access a file, your best bet is to include it in the plugin itself, and then use getClass().getResourceAsStream("/myfile.txt") to get an InputStream that you can read the contents for.

关于eclipse - 尝试通过ResourcesPlugin获取工作区时出现"Workspace is closed"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/962364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com