如何获取 Eclipse 工作区位置 URI

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11692636/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 18:41:15  来源:igfitidea点击:

how to get Eclipse Workspace Location URI

eclipseeclipse-plugin

提问by VamsiKrishna

I am working on a plugin, which passes the location URI of current workspace to other method.

我正在开发一个插件,它将当前工作区的位置 URI 传递给其他方法。

IWorkspace workspace = ResourcesPlugin.getWorkspace();

I am very new to Eclipse PDE. What method returns the URI location of workspace. for Ex if the workspace is C:\Eclipse\Workspace. i need the path C:\Eclipse\Workspace

我对 Eclipse PDE 很陌生。什么方法返回工作区的 URI 位置。例如,如果工作区是 C:\Eclipse\Workspace。我需要路径 C:\Eclipse\Workspace

回答by Chris Gerken

You want:

你要:

ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();

回答by Eugene

Are you sure you need workspace URL? The only thing you may rely is that it will contain .metadata folder - everything else may be located elsewhere:

您确定需要工作区 URL 吗?您唯一可以依赖的是它将包含 .metadata 文件夹 - 其他所有内容都可能位于其他地方:

  1. Projects can be created outside of the workspace.
  2. Workspace files/folders may actually be a links to external resources (that might not even be local files).
  1. 可以在工作区之外创建项目。
  2. 工作区文件/文件夹实际上可能是指向外部资源(甚至可能不是本地文件)的链接。

My recommendation:

我的建议:

  1. If you want to find some resources - use IResource::getLocationURI and check that it is a local file (you may download the content if the URL is EFS)
  2. If you want to access your plugin data (that is in .metadata) use Plugin.getStateLocation
  3. If you still think you need workspace root - Platform.getInstanceLocation
  1. 如果您想查找一些资源 - 使用 IResource::getLocationURI 并检查它是否是本地文件(如果 URL 是 EFS,您可以下载内容)
  2. 如果您想访问您的插件数据(即在 .metadata 中),请使用 Plugin.getStateLocation
  3. 如果您仍然认为您需要工作区根目录 - Platform.getInstanceLocation

回答by elo

Get the absolute file system path of any resource:

获取任何资源的绝对文件系统路径:

IResource.getLocation()