• Intro Headers Instructions Macros
  • Fork me on GitHub
    • Release
    • Introduction
    • How to install bnd
    • Guided Tour
    • Guided Tour Workspace & Projects
    • Concepts
    • Best practices
    • Build
    • Generating JARs
    • Versioning
    • Baselining
    • Service Components
    • Metatype
    • Contracts
    • Manifest Annotations
    • Resolving Dependencies
    • Launching
    • Testing
    • Packaging Applications
    • Wrapping Libraries to OSGi Bundles
    • From the command line
    • For Developers
    • Plugins
    • Tools bound to bnd
    • File Format
    • Header Reference
    • Instruction
    • Instruction Index
    • Macro Reference
    • Command Reference
    • Plugins Reference
    • Settings
    • Errors
    • Warnings
    • Frequently Asked Questions
    Supported by OSGi enRoute
  • packages

    The packages macro provides a query function over the contained packages of a bundle. A simple query language is used to query the packages and filter them. For example if you want to export all packages that are annotated with the @org.example.Export annotation:

    -exportcontents: ${packages;ANNOTATED;org.example.Export}
    

    (NB. using the macro inside Export-Package/Private-Package is an error, because they define the content of the bundle. The packages macro can only be used in the final manifest calculation.).

    All pattern matching is based on fully qualified name and uses the globbing model.

    More examples:

    # List all packages in the bundle, irrespective of how they were included
    All-Packages: ${packages}
    
    # List all packages, alternative syntax
    All-Packages: ${packages;ANY}
    
    # Export packages containing the substring 'export'
    -exportcontents: ${packages;NAMED;*export*}
    
    # Export packages that contain a version. Useful when wrapping existing bundles while keeping exports intact
    -exportcontents: ${packages;VERSIONED}
    

    The following table specifies the available query options:

    Query Parameter Description
    ANY Matches any package
    ANNOTATED PATTERN The package must have an annotation that matches the pattern. The annotation must be either CLASS or RUNTIME retained, and placed on the `package-info.class` for the package.
    NAMED PATTERN The package FQN must match the given pattern.
    VERSIONED Packages that are versioned. Usually this means exported packages.
    • Contact
    • Developers
    • More