2014-10-09 65 views
1

我在資源位於其他文件夾中的插件中創建了鏈接的資源。 一些我想在我的插件中使用這個鏈接資源。但是當我試圖以下面提到的方式獲取bundle和文件url時,它將返回null,因爲只有鏈接在插件中,實際資源坐在其他位置。從eclipse rcp引用鏈接的資源

Bundle bundle = Platform.getBundle("xxxx"); 
    Path path = new Path("resource"); 
    URL url = FileLocator.find(bundle, path, null); 
    URL fileUrl = FileLocator.toFileURL(url); 

對此的任何線索將有所幫助。

回答

0

一種方法是使用IFile

IPath path = new Path("path in the workspace"); 

IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); 

IPath actualPath = file.getLocation(); 
+0

我綁到用你的方法,但仍實際路徑來了空我不知道我是個做錯了.. – Rajesh 2014-10-09 12:16:04

+0

是一個插件罐內此資源或在工作區中?我的代碼只適用於運行時工作區中的資源。我不認爲插件jar中的鏈接完全可以工作。 – 2014-10-09 16:01:34