1

I have own OSGI bundle that have folder inside with some resources. How to read that folder from bundle and get all children of it?

I used before following code.:

    Bundle bundle = Platform.getBundle(bundleID);
    URL fileURL = bundle.getEntry(templatePath);
    URL url = FileLocator.resolve(fileURL);

This code workd utils I exported Eclipse application as Eclipse product.

But I have URL is not hierachical excepiton.

yu.pitomets
  • 1,660
  • 2
  • 17
  • 44

2 Answers2

2

You can use the findEntries method on Bundle to locate files in the bundle and any attached fragments:

Bundle bundle = Platform.getBundle(bundleID);
Enumeration<URL> urls = bundle.findEntries("/folder", "*", false);
Nick Wilson
  • 4,959
  • 29
  • 42
  • Hi Nick. I have a similar problem [**HERE** : *How to copy a resource directory and all included files and sub-folders in a Jar onto another directory*](http://stackoverflow.com/questions/36400436/how-to-copy-a-resource-directory-and-all-included-files-and-sub-folders-in-a-jar). How can I go about copying a resource directory from an OSGi bundle onto another Directory? How can I go about implementing the option you gave here to this end? I will be very grateful if you could help. Thank you in advance. – Program-Me-Rev Apr 04 '16 at 12:15
1

You should write your code in terms of InputStreams and use the method suggested by @NickWilson to retrieve the input streams and use them in your program.

But if you really need that folder exploded on the disk somewhere, you would use org.eclipse.core.runtime.FileLocator.toFileURL(URL) instead of resolve(URL).

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