elipse中路径大全

来源:互联网 发布:mac版本的office 编辑:程序博客网 时间:2024/05/17 07:50

//得到运行是工程路径
Platform.getInstanceLocation().getURL().getPath();

[Java|Eclipse|RCP|Plugin]从插件/RCP中取得文件路径的方法[转载]
从插件中获得绝对路径:
MyPlugin.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();

从编辑器来获得编辑文件:
IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();
IEditorInput input = editor.getEditorInput();
if(input instanceof IFileEditorInput){
IFile file = ((IFileEditorInput)input).getFile();
}

/** 刷新导航树
*/
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = (IResource)root.findMember(new Path("projects"));
IContainer container = (IContainer) resource; 
container.refreshLocal(IResource.DEPTH_INFINITE,null); 

原创粉丝点击