如何获取 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
how to get Eclipse Workspace Location URI
提问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 文件夹 - 其他所有内容都可能位于其他地方:
- Projects can be created outside of the workspace.
- Workspace files/folders may actually be a links to external resources (that might not even be local files).
- 可以在工作区之外创建项目。
- 工作区文件/文件夹实际上可能是指向外部资源(甚至可能不是本地文件)的链接。
My recommendation:
我的建议:
- 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)
- If you want to access your plugin data (that is in .metadata) use Plugin.getStateLocation
- If you still think you need workspace root - Platform.getInstanceLocation
- 如果您想查找一些资源 - 使用 IResource::getLocationURI 并检查它是否是本地文件(如果 URL 是 EFS,您可以下载内容)
- 如果您想访问您的插件数据(即在 .metadata 中),请使用 Plugin.getStateLocation
- 如果您仍然认为您需要工作区根目录 - Platform.getInstanceLocation
回答by elo
Get the absolute file system path of any resource:
获取任何资源的绝对文件系统路径:
IResource.getLocation()