Reputation: 1766
I'm interested how I can read OSGI bundle jar file version with Java before I deploy it? Is there a way to extract this data before deploying it?
Upvotes: 1
Views: 1465
Reputation: 1069
If you just want to get the version it might be completely overkill, but in general a really good way to read all kind of bundle data is to use bnd. Many tools are built on top of bnd, but it's easy to use as a library as well.
Upvotes: 0
Reputation: 6046
You can do it with standard Java:
JarFile jarFile = new JarFile("myjar.jar");
Manifest manifest = jarFile.getManifest();
Attributes mainAttributes = manifest.getMainAttributes();
String bundleVersion = (String) mainAttributes.get(Constants.BUNDLE_VERSION);
Constants class comes from org.osgi.framework package.
Upvotes: 6