• 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
  • endswith ';' STRING ';' SUFFIX

    Prev Next
    Macro
    Check if a string ends with a specific suffix

    Summary

    The endswith macro checks if a given string ends with a specified suffix. If the string ends with the suffix, it returns the string; otherwise, it returns an empty string (which evaluates to false in conditional contexts).

    Syntax

    ${endswith;<string>;<suffix>}
    

    Parameters

    • string - The string to check
    • suffix - The suffix to look for at the end of the string

    Behavior

    • Compares the end of the string with the suffix
    • Returns the original string if it ends with the suffix
    • Returns an empty string (“”) if it does not end with the suffix
    • Case-sensitive comparison
    • Empty string return value is treated as “false” in conditional expressions

    Examples

    Check if a filename ends with .jar:

    ${endswith;mybundle.jar;.jar}
    # Returns: "mybundle.jar"
    

    Check if a string ends with specific text:

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

    Use in conditional logic:

    ${if;${endswith;${project};.test};test-project;regular-project}
    # Checks if project name ends with ".test"
    

    Filter files with specific extension:

    jar.file=${if;${endswith;${@};.jar};${@};}
    

    Check version suffix:

    ${if;${endswith;${version};-SNAPSHOT};snapshot;release}
    

    Use Cases

    • File extension checking
    • String suffix validation
    • Conditional configuration based on naming patterns
    • Filtering lists of values by suffix
    • Validating naming conventions
    • Conditional manifest header generation

    Notes

    • The comparison is case-sensitive
    • Returns the original string (truthy) on match, empty string (falsy) on no match
    • Useful in combination with ${if} macro for conditional logic
    • See also: ${startswith} for checking string prefixes

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home