이 콘텐츠는 선택한 언어로 제공되지 않습니다.

2.4. API Bundle


Overview

This section explains how to set up a Maven project for a typical API bundle.
The hello-paris bundle exemplifies an API bundle, which contains only public Java interfaces. Hence, the API bundle should export all of its own packages and associate a version number with the exported packages.

Directory structure

The hello-paris bundle has the following directory structure:
hello-paris/
  |
  \--src/
     |
     \--main/
     |  |
     |  \--java/
     |     |
     |     \--org/fusesource/example/hello/paris/
     |        |
     |        \-HelloParis.java
     |   
     \--test/
Copy to Clipboard Toggle word wrap
The Java source code is located under the src/main/java sub-directory. The org.fusesource.example.hello.paris 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 API

The hello-paris bundle is a pure API, which means it contains only Java interfaces. In this example, there is a single interface, HelloParis, which returns a localized greeting and a Clock object that tells the local time. The HelloParis interface is defined as follows:
// Java
package org.fusesource.example.hello.paris;

import org.fusesource.example.time.Clock;

public interface HelloParis {
    public String getGreeting();
    
    public Clock getLocalTime();
}
Copy to Clipboard Toggle word wrap

Maven dependencies

In the Maven POM file, the hello-paris bundle defines dependencies on the following Maven artifact:
  • time-util

Import and export rules

The following import and export rules apply to the hello-paris bundle:
  • Exporting own packages—the org.fusesource.example.hello.paris package is public, and must be exported.
  • Importing own packages—none of the bundle's own packages should be imported.
  • Importing dependent packages—any external package dependencies must be imported.

Maven bundle plug-in settings

The Maven bundle plug-in is configured to export the API package, org.fusesource.example.hello.paris (coded as ${project.groupId}.hello.paris*). 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:
<instructions>
  <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
  <Import-Package>*</Import-Package>
  <Export-Package>
    !${project.groupId}*.impl*,
    !${project.groupId}*.internal*,
	${project.groupId}.hello.paris*;version=${project.version}
  </Export-Package>
</instructions>
Copy to Clipboard Toggle word wrap

Generated MANIFEST.MF file

When you build the bundle using Maven, the Maven bundle plug-in automatically generates the following MANIFEST.MF file:
Manifest-Version: 1.0
Bundle-Name: hello-paris
Built-By: JBLOGGS
Build-Jdk: 1.5.0_08
Created-By: Apache Maven Bundle Plugin
Import-Package: org.fusesource.example.time;version="[1.0,2)"
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.fusesource.example.hello-paris
Tool: Bnd-1.15.0
Bnd-LastModified: 1296826928285
Export-Package: org.fusesource.example.hello.paris;uses:="org.fusesour
 ce.example.time";version="1.0"
Bundle-Version: 1.0.0
Copy to Clipboard Toggle word wrap
The Import-Package header lists one external package dependency, org.fusesource.example.time. None of the bundle's own packages are imported.
The Export-Package header is used to export the API package, org.fusesource.example.hello.paris, while the uses clause declares a transitive dependency on the org.fusesource.example.time package.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat