0

Let's suppose I have Bundle bundle=...; Can I get this OSGi bundle's filename? I've searched but didn't find anything. The only thing I can do now is to get bundle symbolic name via headers, but it's not filename as symbolic name is set in manifest and can be not equal to filename.

toniedzwiedz
  • 17,895
  • 9
  • 86
  • 131
  • 1
    Have you tried `bundle.getLocation`? – toniedzwiedz Apr 19 '15 at 07:15
  • As far as I can remember, it should give you the path to the jar file so you could just chop its name off this value. However, you should keep in mind that the value returned will not change while the bundle is installed, even if you update it (possibly with a differently named file). Let me know if it works for you. If it does, I'll post this as an answer. – toniedzwiedz Apr 19 '15 at 07:23

1 Answers1

2

The answer, in general, is no. The OSGi specification does not require that the framework preserve the jar file. For example, an OSGi framework implementation can expand the jar file into the file system or put the contents in a database. It is free to store the bundle contents in any way it desires.

Implementation of the OSGi framework may provide non-standard ways to locate the jar, if it still exists. I believe Equinox provides a FileLocator service which can be used for this.

BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27