Search

Chapter 9. Deploying a Plain JAR

download PDF

Abstract

This chapter explains how to deal with plain JAR files (typically libraries) that contain no deployment metadata whatsoever. That is, a plain JAR is neither a WAR, nor an OSGi bundle.
If the plain JAR occurs as a dependency of a bundle, you must add bundle headers to the JAR . If the JAR exposes a public API, typically the best solution is to convert the existing JAR into a bundle, enabling the JAR to be shared with other bundles. This chapter describes how to perform the conversion process automatically, using the open source Bnd tool.

9.1. Bundle Tool (Bnd)

About the bnd tool

The Bnd tool is a an open source utility for creating and diagnosing OSGi bundles. It has been developed by Peter Kriens and is freely downloadable from the aQute Web site (subject to an Apache version 2.0 open source license). The key feature of the Bnd tool is that it automatically generates Manifest headers for the OSGi bundle, thus relieving you of this tedious task. The main tasks that Bnd can perform are:
  • Print the manifiest and show the package dependencies of a JAR file or bundle file.
  • Wrap a vanilla JAR file, converting it into a bundle.
  • Build a bundle from the class path, based on specifications in a .bnd file.
  • Validate manifest entries.
You have the option of invoking Bnd in any of the following ways: from the command line; as an Ant task; or through the Maven bundle plug-in, maven-bundle-plugin. In fact, the approach to building bundles described in Chapter 3, Building with Maven is based on the Maven bundle plug-in and therefore, implicitly, is also based on the Bnd tool.

Downloading and installing bnd

You can download Bnd from the aQute Web site at the following location:
http://www.aqute.biz/Bnd/Bnd
Download the Bnd JAR file, bnd-Version.jar, to a convenient location. There is no installation involved: the JAR file is all that you need to use the Bnd tool. For convenience, however, it is advisable to rename the JAR file to bnd.jar, so you won't have to do so much typing when you invoke it from the command line (for example, as in java -jar bnd.jar Cmd Options)

References

To learn more about the Bnd tool, consult the following references:
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.