开发者

Access relative path from eclipse-plugin

Does anyone know how to get a file with uri from a self-made Eclipse Plug-in?

Absolute paths would be no problem:

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

But how do I access local resources relatively?

URI.createFileURI("jar:file:/%ECLIPSE_HOME%/plugins/SMartGen.jar!StarSchema.profile.uml"开发者_Python百科);

doesn't work this way....

Happy for every answer.

lg martin


Use the FileLocator.

Example:

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

This will get the URL of a file "someIcon.png" that is located in the "icons" folder in the bundle "myBundle".


For getting a resource out of eclipse, you can use org.osgi.framework.Bundle.getEntry(String). That returns a standard java.net.URL, which can also be used to get the InputStream for consumption. It has the advantage of not caring if your plugin is in directory form, jar form, or in your workspace.

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

URL has a handy toURI() method as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜