1.得到runtime workspace目录的绝对路径
String file = Platform.getInstanceLocation().getURL().getPath();
2.得到runtime workspace目录下所有的工程
IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IProject[] newProjectHandle = root.getProjects(); for (int i = 0, size = newProjectHandle.length; i < size; i++) { IProject iProject = newProjectHandle[i]; // 工程名字 String projectName = iProject.getName(); IResource[] resources = iProject.members(); for (int j = 0, n = resources.length; j < n; j++) { if (resources[j].getType() == IResource.FILE && resources[j].getFileExtension().equals("xpdl")) { // 包:工程下xpdl文件的绝对路径,包路径 String xpdlFileFullPath = resources[j].getLocation() .toOSString(); }}
3.取插件项目所在路径
public static String getPluginPath(){ String pluginPath=null; try { pluginPath = FileLocator.toFileURL( Platform.getBundle(Activator.PLUGIN_ID).getEntry("")).getPath(); pluginPath = pluginPath.substring(1); } catch (IOException e1) { // TODO 自动生成 catch 块 e1.printStackTrace(); } return pluginPath; }
本文介绍了如何使用Java代码在Eclipse环境中获取运行时工作空间的绝对路径、列出工作空间下的所有项目以及获取特定类型文件(如xpdl)的完整路径,并提供了一种方法来获取插件项目的所在路径。
4988

被折叠的 条评论
为什么被折叠?



