Recall that library bundles export utility classes but do not register services of their own. Selectively exporting some of the packages inside a library bundle makes it possible for callers to benefit from the changes immediately after an update. To accomplish this, you can design the library in an interface-provider fashion. For example, consider the following bundle:
META-INF/MANIFEST.MF com/acme/util/Sort.class com/acme/util/impl/QuickSort.class com/acme/util/impl/BubbleSort.class com/acme/util/impl/MergeSort.class
You may then declare
Export-Package: com.acme.util
in the manifest to export only the com.acme.util package containing the class Sort. A caller can pick an algorithm for sorting by writing code such as
Sort s = Sort.getInstance("QuickSort"); s.sort(anArray);
The specific sorting algorithm implementations are hidden in the com.acme. util.impl package, which cannot be accessed by callers from other bundles. When the implementations of the library bundle are updated, the changes can take effect immediately without requiring framework restart.
3.133.158.36