1. 得到某PLUGIN的路径:
Platform.getBundle("mypluginid").getLocation()
2.eclipse采用osgi后好像还可以: (前提是这个插件有Activator这个类.这个类继承了ECLIPSE的Plugin类)
Activator.getDefault().getBundle().getLocation()
3.eclipse采用osgi前好像好像是: (前提是这个插件有MyPlugin这个类.这个类继承了ECLIPSE的Plugin类)
MyPlugin.getDefault().getBundle().getLocation()
4.得到工作区路径:
Platform.getlocation(); ResourcesPlugin.getWorkspace(); Platform.getInstanceLocation();
5.得到ECLIPSE安装路径
Platform.getInstallLocation();
6.从插件中获得绝对路径:
AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath()
7.通过文件得到工程Project:
IProject project = ((IFile)o).getProject();
8.通过文件得到全路径:(这行代码尽然不能使用代码格式显示,eye太诡异了)
String path =((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();
9.获得工作空间workspace:
(1)得到Appliaction workspace:
Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();
(2)得到runtime workspace:
Platform.getInstanceLocation().getURL().getPath();
10.得到整个Workspace的根:
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
11.从根来查找资源:
IResource resource = root.findMember(new Path(containerName));
12.从Bundle来查找资源:
Bundle bundle = Platform.getBundle(pluginId); URL fullPathString = BundleUtility.find(bundle, filePath);
13. 从编辑器来获得编辑文件
IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart(); IEditorInput input = editor.getEditorInput(); if(input instanceof IFileEditorInput){ IFile file = ((IFileEditorInput)input).getFile(); }
14.获取插件的绝对路径:
FileLocator.resolve(BuildUIPlugin.getDefault().getBundle().getEntry("/")).getFile();
15.得到插件所在的路径:
Platform.asLocalURL(Platform.getBundle("your plugin ID").getEntry("")).getFile();
16.得到当前工作空间的路径:
Platform.getInstanceLocation().getURL().getFile();
17.得到当前工作空间下的所有工程:
ResourcesPlugin.getWorkspace().getRoot().getProjects();
18.得到某 PLUGIN 的路径:
Platform.getBundle("mypluginid").getLocation()
19.eclipse采用osgi后好像还可以:(前提是这个插件有Activator这个类.这个类继承了ECLIPSE的Plugin类)
Activator.getDefault().getBundle().getLocation();
20.eclipse采用osgi前好像好像是:(前提是这个插件有MyPlugin这个类.这个类继承了ECLIPSE的Plugin类)
MyPlugin.getDefault().getBundle().getLocation();
21.得到工作区路径:
Platform.getlocation(); ResourcesPlugin.getWorkspace(); Platform.getInstanceLocation();
22.得到ECLIPSE安装路径:
Platform.getInstallLocation();
23.从插件中获得绝对路径:
AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath();
24.通过文件得到 Project:
IProject project = ((IFile)o).getProject();
25.通过文件得到全路径:
String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();
26. 得到整个Workspace的根:
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
27.从根来查找资源:
IResource resource = root.findMember(new Path(containerName));
28.从Bundle来查找资源:
Bundle bundle = Platform.getBundle(pluginId); URL fullPathString = BundleUtility.find(bundle, filePath);
29.得到 Appliaction workspace:
Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();
30.得到 runtimeworkspace:
Platform.getInstanceLocation().getURL().getPath();
31.从编辑器来获得编辑文件:
IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart(); IEditorInput input = editor.getEditorInput(); if(input instanceof IFileEditorInput) { IFile file = ((IFileEditorInput)input).getFile(); }
32.获取插件的绝对路径:
FileLocator.resolve(BuildUIPlugin.getDefault().getBundle().getEntry("/")).getFile();
33.Platform类获取路径汇总:
假定Eclipse的安装路径为:D:\Java\eclipse
创建的Workspace路径为:D:\Java\eclipse\workspace
Platform.getNL():zh_CN Platform.getWS():win32 Platform.getOS():win32 Platform.getOSArch():x86 Platform.getStateStamp():155 Platform.getUserLocation().getURL():file:/D:/Profiles/windowsloginname/user/ Platform.getInstallLocation().getURL():file:/d:/Java/eclipse/ Platform.getConfigurationLocation().getURL():file:/d:/Java/eclipse/configuration/ Platform.getInstanceLocation().getURL():file:/D:/Java/eclipse/workspace/ Platform.getLocation():D:/Java/eclipse/workspace Platform.getLocation().toOSString():D:\Java\eclipse\workspace Platform.getLogFileLocation():D:/Java/eclipse/workspace/.metadata/.log Platform.getLogFileLocation().toOSString():D:\Java\eclipse\workspace\.metadata\.log Platform.getPluginStateLocation(Platform.getPlugin("NamedPlugin")):D:/Java/eclipse/workspace/.metadata/.plugins/NamedPlugin Platform.getPlugin("NamedPlugin").getStateLocation():D:/Java/eclipse/workspace/.metadata/.plugins/NamedPlugin Platform.getPlugin("NamedPlugin").getDescriptor():NamedPlugin_1.0.0 Platform.getPlugin("NamedPlugin").getDescriptor().getLabel():Plug-in Name Platform.getPlugin("NamedPlugin").getDescriptor().getProviderName():ProviderName Platform.getPlugin("NamedPlugin").getDescriptor().getUniqueIdentifier():NamedPlugin Platform.getPlugin("NamedPlugin").getDescriptor().getInstallURL():platform:/plugin/NamedPlugin_1.0.0/ Platform.getPlugin("NamedPlugin").getDescriptor().getInstallURL().getPath():/plugin/NamedPlugin_1.0.0/