6.2. Designing Library Bundles

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 ...

Get Programming Open Service Gateways with Java Embedded Server™ Technology now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.