Eclipse取得路径的方法
2016-04-21 19:56
543 查看
在eclipse插件开发中很实用的路径获取
转自 http://liugang594.iteye.com/blog/530974
从插件中获得绝对路径:
TestPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());
通过文件得到Project:
IProject project = ((IFile)o).getProject();
通过文件得到全路径:
String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();
得到整个Workspace的根:
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
从根来查找资源:
IResource resource = root.findMember(new Path(containerName));
从Bundle来查找资源:
Bundle bundle = Platform.getBundle(pluginId);
URL fullPathString = BundleUtility.find(bundle, filePath);
得到Appliaction workspace:
Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();
得到runtimeworkspace:
Platform.getInstanceLocation().getURL().getPath();
得到工作目录路径
Platform.getlocation()
从编辑器来获得编辑文件
IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();
IEditorInput input = editor.getEditorInput();
if(input instanceof IFileEditorInput){
IFile file = ((IFileEditorInput)input).getFile();
}
转自 http://liugang594.iteye.com/blog/530974
从插件中获得绝对路径:
TestPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());
通过文件得到Project:
IProject project = ((IFile)o).getProject();
通过文件得到全路径:
String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();
得到整个Workspace的根:
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
从根来查找资源:
IResource resource = root.findMember(new Path(containerName));
从Bundle来查找资源:
Bundle bundle = Platform.getBundle(pluginId);
URL fullPathString = BundleUtility.find(bundle, filePath);
得到Appliaction workspace:
Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();
得到runtimeworkspace:
Platform.getInstanceLocation().getURL().getPath();
得到工作目录路径
Platform.getlocation()
从编辑器来获得编辑文件
IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();
IEditorInput input = editor.getEditorInput();
if(input instanceof IFileEditorInput){
IFile file = ((IFileEditorInput)input).getFile();
}
相关文章推荐
- SSH:Struts has detected an unhandled exception
- 快速构建Spring boot项目(功能是检测访问页面的设备)
- Struts2中namespace的用法
- struts --interceptor
- 如何在Eclipse中查看JDK类库的源代码 【转】
- Eclipse将输出结果保存到文件中
- Java urlrewrite+Maven 简单使用
- Java Calendar 基础详解实例
- struts--Action解读
- HashMap内部实现原理
- java并发之Lock与synchronized的区别
- Java加密技术(一)——BASE64与单向加密算法MD5&SHA&MAC
- Spark-submit 时出现java.lang.ClassNotFoundException
- java容器学习
- java 链表 树
- java并发之Lock
- Java读取properties文件中文乱码问题解决
- struts2动态方法调用
- java发送get/post请求
- 20160421javaweb之上传下载小案例---网盘