Eclipse插件获取Eclipse的根目录
String eclipseRoot = Platform.getInstallLocation().getURL().toString(); eclipseRoot = eclipseRoot.replace("file:/", "");
Eclipse插件获取Workspace根目录
//方法1 String workspaceRoot= Platform.getInstanceLocation().getURL().toString(); workspaceRoot = workspaceRoot.replace("file:/", ""); //方法2 String path = Activator.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath();
Eclipse插件获取User根目录
String userHome = Platform.getUserLocation().getURL().toString(); userHome = userHome.replace("file:/", "");
Elclipse插件获取Bundle的OSGI路径
//方法1 String bundlePath = Activator.getDefault().getBundle().getLocation(); String pathBundle = bundlePath.replace("reference:file:/",""); //方法2 Bundle bundle = Platform.getBundle("bundle id"); URL urlentry = bundle.getEntry("bundle resource path"); String strEntry = FileLocator.toFileURL(urlentry).getPath(); //方法3 String pathClass = KeyHandler.class.getResource("resource path").getFile();