• Intro Headers Instructions Macros Commands
Fork me on GitHub
    • Getting Started
      • Introduction
      • How to install bnd
      • Guided Tour Workspace & Projects
      • bnd / bndlib Features and JAR Wrapping Techniques
      • FAQ - Frequently Asked Questions
    • Concepts and Practices
      • Concepts
      • Background
      • Best practices
    • Build and Development
      • Build
      • Generating JARs
      • Versioning
      • Baselining
      • Service Components
      • Metatype
      • Contracts
      • Bundle Annotations
      • Accessor Properties
      • SPI Annotations
    • Dependency and Launching
      • Resolving Dependencies
      • Launching
      • Startlevels
    • Testing
      • Testing
      • Testing with Launchpad
    • Packaging and Distribution
      • Packaging Applications
      • JPMS Libraries
      • Wrapping Libraries to OSGi Bundles
    • Documentation and Tools
      • Generating Documentation
      • bnd CLI Commands
      • For Developers
      • Templates for Workspaces
      • Tips for Windows users
      • Tools bound to bnd
    • Reference Material
      • Reference
      • Headers
      • Instruction Reference
      • Instruction Index
      • Macro Reference
      • Macro Index
      • Plugins
      • External Plugins
    • Configuration and Troubleshooting
      • Settings
      • Errors
      • Warnings
  • base64 ';' FILE [';' LONG ]

    Prev Next
    Macro
    Encode a file's contents as Base64 text

    Summary

    The base64 macro reads a file and returns its contents encoded as a Base64 string. This is useful for embedding binary content or file data directly in text-based configuration files.

    Syntax

    ${base64;<file>[;fileSizeLimit]}
    

    Parameters

    • file - Path to the file to encode (relative to the project directory)
    • fileSizeLimit (optional) - Maximum file size in bytes (default: 100,000 bytes)

    Behavior

    • Reads the entire file into memory
    • Encodes the file contents as Base64
    • Enforces a size limit to prevent memory issues with large files
    • Throws an exception if the file exceeds the size limit
    • File path is resolved relative to the current project directory

    Examples

    Encode a small binary file:

    ${base64;resources/icon.png}
    

    Encode with custom size limit (1MB):

    ${base64;data/config.bin;1000000}
    

    Embed a certificate in a property:

    certificate.data=${base64;certs/ca-cert.pem}
    

    Use Cases

    • Embedding small binary resources in manifest files
    • Including certificates or keys in configuration
    • Encoding binary data for transmission in text formats
    • Creating data URIs for embedded content
    • Storing binary configuration data in properties files

    Notes

    • Default size limit is 100,000 bytes to prevent memory exhaustion
    • For large files, consider referencing the file path instead of embedding
    • The encoded output will be approximately 33% larger than the original file

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home