我正在開發一個使用Eclipse插件的Eclipse插件,它將在工具欄中添加一個菜單項。我的插件項目取決於它位於同一插件項目中的一個文件,我想要該文件的路徑。 下面是我用來獲取路徑的示例代碼:從Eclipse中運行運行的同時如何從eclipse插件獲取資源路徑
Bundle bundle = Platform.getBundle("com.feat.eclipse.plugin");
URL fileURL = bundle.getEntry("webspy/lib/file.txt");
File file = null;
String path=null;
try {
file = new File(FileLocator.resolve(fileURL).toURI());
path = file.getAbsolutePath();
} catch (URISyntaxException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
- > Eclipse的應用它給我正確的路徑。但是,當我將我的插件作爲jar導出並添加到我的eclipse插件文件夾中時,它不會給我正確的路徑。請幫我解決這個問題。
謝謝格雷格,它爲我工作。 – user3355101