Exporting Packages

An OSGi bundle’s Java packages are private by default. To expose a package, you must explicitly export it. This way you share only the classes you want to share. Exporting a package in your OSGi bundle (bundle) manifest makes all the package’s classes available for other bundles to import.

To export a package, add it to your module’s or plugin’s Export-Package OSGi header. A header exporting com.liferay.petra.io and com.liferay.petra.io.unsync would look like this:


The correct location for the header depends on your project’s type:

Project TypeExport-Package header location
Module JAR (uses bnd)[project]/bnd.bnd
Module JAR (doesn’t use bnd)[module JAR]/META-INF/MANIFEST.MF
Plugin WARWEB-INF/liferay-plugin-package.properties

Module projects created using Blade CLI, Liferay’s Maven archetypes, or Liferay Dev Studio DXP use bnd. On building such a project’s module JAR, bnd propagates the OSGi headers from the project’s bnd.bnd file to the JAR’s META-INF/MANIFEST.MF.

In module projects that don’t use bnd, you must manually add package exports to an Export-Package header in the module JAR’s META-INF/MANIFEST.MF.

In plugin WAR projects, you must add package exports to an Export-Package header in the project’s WEB-INF/liferay-plugin-package.properties. On copying the WAR into the [Liferay Home]/deploy folder, the WAB Generator propagates the OSGi headers from the WAR’s liferay-plugin-package.properties file to the META-INF/MANIFEST.MF file in the generated Web Application Bundle (WAB).

Now you can share your module’s or plugin’s terrific [EDITOR: or terrible!] packages with other OSGi bundles!

Configuring Dependencies

Deploying WARs (WAB Generator)

Project Templates

Liferay’s Maven Archetypes

Blade CLI

Liferay Dev Studio DXP

Semantic Versioning

« Importing PackagesSemantic Versioning »
Was this article helpful?
0 out of 0 found this helpful