1.
public class PathUtil {
public static String getAbsolutePath() {
final String pluginId = TestPlugin.PLUGIN_ID;
final Bundle bundle = Platform.getBundle(pluginId);
if (bundle != null) {
final URL url = bundle.getEntry("src\\test\\yang\\path\\PathUtil.java");
try {
final URL fileURL = FileLocator.toFileURL(url);
final String path = fileURL.getPath();
final File file = new File(path);
final String absolutePath = file.getAbsolutePath();
System.out.println(absolutePath);
return absolutePath;
} catch (final IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return "error";
}
2.getEntry、getResource方法中,必须是插件根目录中的文件,如果是images/a.png是取不到的,只能先取到images文件,再取images中的文件;
3.