从eclipse-plugin访问相对路径

时间:2011-06-06 14:53:46

标签: eclipse eclipse-plugin eclipse-rcp uri relative-path

有没有人知道如何使用自制Eclipse插件获取uri文件?

绝对路径没问题:

URI.createFileURI("C:/Users/hp/workspace(dke)/SMartGen/StarSchema.profile.uml");

但是如何相对访问本地资源?

URI.createFileURI("jar:file:/%ECLIPSE_HOME%/plugins/SMartGen.jar!StarSchema.profile.uml");

这种方式不起作用....

对每一个答案都感到高兴。

lg martin

2 个答案:

答案 0 :(得分:3)

使用FileLocator

实施例:

URL iconUrl = FileLocator.find(Platform.getBundle("myBundle"), new Path("icons/someIcon.png"), null);

这将获取文件“someIcon.png”的URL,该文件位于“myBundle”包中的“icons”文件夹中。

答案 1 :(得分:0)

为了从eclipse中获取资源,您可以使用org.osgi.framework.Bundle.getEntry(String)。返回标准java.net.URL,也可用于获取InputStream消费。如果您的插件是目录形式,jar形式或工作区中,它的优点是不关心。

Bundle bundle = FrameworkUtil.getBundle(MyClass.class);
URL url = bundle.getEntry("StarSchema.profile.uml");

网址也有一个方便的toURI()方法。

相关问题