concept dynamic import in category osgi

appears as: dynamic import, dynamic imports, dynamic import
Enterprise OSGi in Action

This is an excerpt from Manning's book Enterprise OSGi in Action.

Dynamic package imports indicate to the OSGi framework that it should attempt to wire the package when the bundle first attempts to load something from it. If the wiring fails, then so does the attempt to load the resource. Critically, when a dynamic import has been successfully wired, it’s wired for good. At this point, a dynamic import is no different from a normal one.

Another key difference between dynamic imports and normal imports is that dynamic imports can be defined using wildcards, as follows. This allows a bundle to import a package that’s unknown when the bundle manifest is created. This is one of the most useful features of the DynamicImport-Package header:

OSGi in Action: Creating Modular Applications in Java

This is an excerpt from Manning's book OSGi in Action: Creating Modular Applications in Java.

Dynamic imports are alluring to new OSGi programmers because they provide behavior similar to that in standard Java programming, where everything available on the class path is visible to the bundle. Unfortunately, this approach isn’t modular and doesn’t allow the OSGi framework to verify whether dependencies are satisfied in advance of using a bundle. As a result, dynamically importing packages should be seen as bad practice, except for explicitly dealing with legacy SPI approaches.

How would this example change if you wanted to treat the logging package as a dynamic import? The impact to the Logger class is as follows.

Listing 5.3. Simple proxy logger using dynamic import

Both are used to express dependencies on packages that may or may not be available at execution time. Although this is the specific use case for optional imports, it’s a byproduct of dynamic imports. Either way, this has the following impact: