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; }