I have an OSGi bundle that can also run in plain Java process. I need to be able to tell if the bundle was loaded in an OSGi system or not. How can I do that? If there is no OSGi-standard way of doing this, I will settle for Eclipse/Equinox-specific approach.
OSGi facilitates creating and managing modular Java components (called bundles) that can be deployed in a container. As a developer, you use the OSGi specification and tools to create one or more bundles. OSGi defines the lifecycle for these bundles. It also hosts them and supports their interactions in a container.
OSGi is a Java framework for developing and deploying modular software programs and libraries. Each bundle is a tightly coupled, dynamically loadable collection of classes, jars, and configuration files that explicitly declare their external dependencies (if any).
Procedure. Install the plug-in bundle into the Eclipse Equinox OSGi framework with the OSGi console. Start the Eclipse Equinox framework with the console enabled. Install the plug-in bundle in the Equinox console.
Add Bundle-Activator to your MANIFEST.MF. If it gets instantiated, then your JAR is running in an OSGi container.
If you don't have an activator, you can also try asking for your bundle:
Bundle b = org.osgi.framework.FrameworkUtil.getBundle(MyClass.this);
If it returns null, your class wasn't loaded by OSGi.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With