0

I've developed a sample OSGI bundle and deployed it into Karaf, and the bundle contains a folder on the same level as the source.

My class needs to load data from this folder, but I got an error each time:

java.lang.IllegalArgumentException: No such group file: ./data/...

My question is: how do I use a relative path to a folder inside an OSGI Bundle?

Hannele
  • 9,301
  • 6
  • 48
  • 68
issamux
  • 1,336
  • 1
  • 19
  • 35
  • thanks for suchs advices ... a sample error of typing is not the end of the world ... and i m not expecting from guys like u any thinks ... just to go their way and let the other response or moderate a dummy typing mistake ,instead of writing article of 5 ligne blablablaa... – issamux Sep 15 '14 at 11:50
  • I asked you to read only once that you have written down. Not more. If you are such a big enemy of quality, I must suggest you not to try develop based on OSGi as you will never have a sense of achievement with it. Btw: This is the first time I raised my voice against the exceptionally poor quality of the question. – Balazs Zsoldos Sep 15 '14 at 12:12
  • hhhh ok man , take it easy ,and thanks for advices ... btw , i solved the problem,...to not continue developing in OSGI ? – issamux Sep 15 '14 at 12:24

2 Answers2

1

Did you try Bundle.getEntry? It is one the methods that can be used to access the contents of a bundle.

BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27
  • already try it , Bundle.getEntry Bundle.getResource, my bundle call an other one and pass to it this Path , i think the second plugin responsable of this problem.... thanks :) – issamux Sep 15 '14 at 11:45
0

solved using context from bundle:

URL wfl = context.getBundle().getResource("data1/file.txt");

or

URL url = MyClass.class.getClassLoader().getResource("data1/file.txt");
            if (url != null) {          
                mFile = FileLocator.toFileURL(url).getFile();

Hope this help someone

issamux
  • 1,336
  • 1
  • 19
  • 35