• 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
  • startswith ';' STRING ';' PREFIX

    Prev Next
    Macro
    Check if a string starts with a specific prefix

    Summary

    The startswith macro checks if a given string starts with a specified prefix. Returns the string if it matches, empty string otherwise.

    Syntax

    ${startswith;<string>;<prefix>}
    

    Parameters

    • string - The string to check
    • prefix - The prefix to look for

    Behavior

    • Checks if string starts with the prefix
    • Returns the original string if it starts with prefix
    • Returns empty string (“”) if it doesn’t
    • Case-sensitive comparison

    Examples

    Check string prefix:

    ${startswith;com.example.api;com.example}
    # Returns: "com.example.api"
    

    Check with non-matching prefix:

    ${startswith;org.other.package;com.example}
    # Returns: ""
    

    Use in conditional:

    ${if;${startswith;${project};test.};test-project;regular-project}
    

    Filter list by prefix:

    ${filter;${packages};${startswith;.*;com\.example}}
    

    Use Cases

    • String prefix validation
    • Package name filtering
    • Path matching
    • Conditional logic based on prefixes
    • Name pattern checking

    Notes

    • Case-sensitive comparison
    • Returns truthy (string) or falsy (empty) value
    • Useful with ${if} for conditional logic
    • See also: ${endswith} for suffix checking
    • See also: ${matches} for regex matching

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home