Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
2.3. Library Bundle
Overview 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
This section explains how to set up a Maven project for a typical library bundle.
The
time-util bundle exemplifies a library bundle, where the main purpose of a library is to make interfaces and classes available to other bundles. Hence, the library should export all of its own packages and associate a version number with the exported packages.
Directory structure 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Assuming it is built as a Maven project, the
time-util bundle has the following directory structure:
The Java source code is located under the
src/main/java sub-directory. The org.fusesource.example.time package is public and all of its classes and interfaces can be exported from the bundle.
There are no blueprint resources associated with this bundle.
Sample implementation 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The
time-util bundle is essentially a wrapper around some of the standard time utilities in Java. It provides a Clock class, which returns the local time in a particular time zone when you invoke the Clock.getLocalTime() method. The Clock class is defined as follows:
The
TimeUtil class is a factory that is used to create Clock instances for particular time zones. Two time zones are supported: TimeZone.BOSTON and TimeZone.PARIS. The TimeUtil class is defined as follows:
Import and export rules 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The following import and export rules apply to the
time-util bundle:
- Exporting own packages—the
org.fusesource.example.timepackage is public, and must be exported. - Importing own packages—none of the bundle's own packages should be imported, which is the usual case for a library bundle.
- Importing dependent packages—any external package dependencies must be imported. In this particular example, however, there are none (the
time-utilbundle depends only on classes from the JVM).
Maven bundle plug-in settings 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The Maven bundle plug-in is configured to export the library package,
org.fusesource.example.time (coded as ${project.groupId}.time). The Export-Package instruction also contains entries to block the export of any packages containing .impl or .internal. In this case, the bundle plug-in instructions are as follows:
Generated MANIFEST.MF file 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
When you build the bundle using Maven, the Maven bundle plug-in automatically generates the following
MANIFEST.MF file: