Reputation: 1415
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?
Upvotes: 0
Views: 1416
Reputation: 1415
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
Upvotes: 0
Reputation: 9384
Did you try Bundle.getEntry? It is one the methods that can be used to access the contents of a bundle.
Upvotes: 1