3

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");

doesn't work this way....

Happy for every answer.

lg martin

J. Katzwinkel
  • 1,923
  • 16
  • 22
Martin
  • 65
  • 2
  • 4

2 Answers2

3

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".

Sandman
  • 9,610
  • 8
  • 36
  • 41
  • but now i got another problem with changing java.net.URL to org.eclipse.emf.common.util.URI url.toUri() and util.URI is in some kind not the same I will post another question for it. – Martin Jun 08 '11 at 07:11
  • If you really need an absolute URL to the file, use `FileLocator.resolve(url)` on the resulting URL from `FileLocator.find`. – Simon Aug 26 '14 at 13:27
0

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.

Paul Webster
  • 10,614
  • 1
  • 25
  • 32