### Install Embedded FileRepo and Load Exporters Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/plugin.md A typical example demonstrating the installation of an embedded FileRepo and loading all exporters from it. This uses multiple plugin definitions separated by commas. ```properties -plugin.repo.main:\ aQute.lib.deployer.FileRepo; \ name='Main'; \ location=${build}/repo/main, \ aQute.bnd.service.export.Exporter;name=* ``` -------------------------------- ### Start Level Management Agent Example Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/300-launching.md Demonstrates how a management agent placed at start level 1 can control the startup sequence of other bundles, which are set to a higher start level. ```bnd -runbundles: \ org.apache.felix.configadmin;version='[1.8.8,1.8.9)',\ org.apache.felix.http.jetty;version='[3.2.0,3.2.1)';startlevel=100,\ org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\ org.example.management.agent;startlevel=1 osgi.enroute.twitter.bootstrap.webresource;version='[3.3.5,3.3.6)';startlevel=100,\ osgi.enroute.web.simple.provider;version='[2.1.0,2.1.1)' ``` -------------------------------- ### Generate Run Bundles with Start Levels Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/runstartlevel.md This example shows the output of resolving run bundles based on the start level configuration. It lists bundles with their version ranges and assigned start levels. ```bnd -runbundles: \ org.apache.felix.configadmin;version='[1.8.8,1.8.9)';startlevel=1000,\ org.apache.felix.http.jetty;version='[3.2.0,3.2.1)';startlevel=1001,\ org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)';startlevel=1002,\ ... osgi.enroute.twitter.bootstrap.webresource;version='[3.3.5,3.3.6)';startlevel=1019,\ osgi.enroute.web.simple.provider;version='[2.1.0,2.1.1)';startlevel=1020' ``` -------------------------------- ### GET Request with Query Parameters and Environment Variables Source: https://github.com/bndtools/bnd/blob/master/biz.aQute.http.testservers/src/aQute/http/testservers/www/default.html This example shows a GET request to the /get endpoint with the `show_env=1` query parameter. It returns request details along with environment variables, useful for debugging server-side configurations. ```bash $ curl https://httpbin.org/get?show_env=1 { "headers": { "Content-Length": "", "Accept-Language": "en-US,en;q=0.8", "Accept-Encoding": "gzip,deflate,sdch", "X-Forwarded-Port": "443", "X-Forwarded-For": "109.60.101.240", "Host": "httpbin.org", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "User-Agent": "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.83 Safari/535.11", "X-Request-Start": "1350053933441", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.3", "Connection": "keep-alive", "X-Forwarded-Proto": "https", "Cookie": "_gauges_unique_day=1; _gauges_unique_month=1; _gauges_unique_year=1; _gauges_unique=1; _gauges_unique_hour=1", "Content-Type": "" }, "args": { "show_env": "1" }, "origin": "109.60.101.240", "url": "http://httpbin.org/get?show_env=1" } ``` -------------------------------- ### Example bndrun File Configuration Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/300-launching.md This is an example of a bndrun file that specifies the OSGi framework, bundles to install, system properties, and required bundles for launching. ```bndrun -runfw: org.apache.felix.framework;version='[4,5)' -runbundles: \ org.apache.felix.shell,\ org.apache.felix.shell.tui,\ org.apache.felix.scr,\ org.apache.felix.http.jetty,\ org.apache.felix.configadmin,\ org.apache.felix.metatype,\ org.apache.felix.log,\ org.apache.felix.webconsole,\ osgi.cmpn,\ aQute.xray.badbundle;version=latest,\ aQute.xray.plugin;version=latest,\ aQute.xray.hello;version=latest,\ com.springsource.org.apache.commons.fileupload;version=1.2.1,\ com.springsource.org.apache.commons.io;version=1.4.0,\ com.springsource.org.json;version=1.0.0 -runproperties: org.osgi.service.http.port=8080 -runrequires: bundle:(symbolicname=org.apache.felix.shell), bundle:(symbolicname=org.apache.felix.shell.tui), bundle:(symbolicname=org.apache.felix.webconsole), bundle:(symbolicname=org.apache.felix.configadmin), bundle:(symbolicname=org.apache.felix.metatype), bundle:(symbolicname=org.apache.felix.log), bundle:(&(symbolicname=osgi.cmpn)(version>=4.2)),\ bundle:(&(symbolicname=org.apache.felix.scr)(version>=1.6.0)) ``` -------------------------------- ### Specify Bundles for Framework Launch Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/runbundles.md Use the -runbundles instruction to list bundles that should be installed and started when a framework launches. Specify bundle names and version ranges. All necessary bundles must be listed as transitive dependencies are not automatically included. ```properties -runbundles: \ org.apache.felix.configadmin;version='[1.8.8,1.8.9)',\ org.apache.felix.http.jetty;version='[3.2.0,3.2.1)',\ org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\ ... osgi.enroute.twitter.bootstrap.webresource;version='[3.3.5,3.3.6)',\ osgi.enroute.web.simple.provider;version='[2.1.0,2.1.1)' ``` -------------------------------- ### Include Packages Matching a Pattern Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/conditionalpackage.md This example demonstrates how to include all packages starting with 'aQute.lib' that are referenced by the current JAR's contents. The packages will be copied into the bundle as private resources. ```bnd -conditionalpackage: aQute.lib* ``` -------------------------------- ### Setup Local Docs Development Environment (MacOS) Source: https://github.com/bndtools/bnd/blob/master/docs/README.md Commands to set up the local development environment on macOS, including installing rbenv, a specific Ruby version, and starting the dev server. ```bash brew install rbenv rbenv init rbenv install 3.4.5 rbenv local 3.4.5 ./run.sh ``` -------------------------------- ### Assign Start Level with Least Dependencies First Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/runstartlevel.md This example demonstrates assigning start levels to bundles. It uses 'leastdependenciesfirst' for ordering, starts at level 1000, and increments by 1 for each subsequent bundle. ```properties -runstartlevel: \ order = leastdependenciesfirst, \ begin = 1000, \ step = 1 ``` ```properties -runbundles: \ org.apache.felix.configadmin;version='[1.8.8,1.8.9)';startlevel=1000,\ org.apache.felix.http.jetty;version='[3.2.0,3.2.1)';startlevel=1001,\ org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)';startlevel=1002,\ ... osgi.enroute.twitter.bootstrap.webresource;version='[3.3.5,3.3.6)';startlevel=1019,\ osgi.enroute.web.simple.provider;version='[2.1.0,2.1.1)';startlevel=1020 ``` -------------------------------- ### Example -runbundles Instruction Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/runbundles.md This example shows how to specify bundles with their versions, including workspace bundles and those from repositories. ```bnd -runbundles=osgi;version="[4.1,4.2)", junit.junit, com.acme.foo;version=project ``` -------------------------------- ### Setting Framework Beginning Start Level Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/300-launching.md Use the `-runproperties` instruction to specify the initial start level for the OSGi framework. This is particularly useful when a start level management agent is present. ```bnd -runproperties: \ org.osgi.framework.startlevel.beginning=1 ``` -------------------------------- ### Example Component Configuration Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/200-components.md An example demonstrating the usage of @Component and @Reference annotations and the resulting OSGI-INF XML. ```APIDOC ## Example Component Configuration Assume the JAR contains the following class: package com.acme; import org.osgi.service.event.*; import org.osgi.service.log.*; import aQute.bnd.annotation.component.*; @Component public class AnnotatedComponent implements EventHandler { LogService log; @Reference void setLog(LogService log) { this.log=log; } public void handleEvent(Event event) { log.log(LogService.LOG_INFO, event.getTopic()); } } The only thing necessary to register the Declarative Service component is to add the following Service-Component header: Service-Component: com.acme.* This header will look for annotations in all com.acme sub-packages for an annotated component. The resulting XML will look like: OSGI-INF/com.acme.AnnotatedComponent.xml: The following example shows a component that is bound to the log service via the setLog method without annotations: ``` -------------------------------- ### Example -builderignore Configuration Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/builderignore.md This example shows how to configure -builderignore with conditional logic based on the driver. Paths are relative to the project. ```bnd -builderignore=${if;${driver;gradle};bin,bin_test,generated;build} ``` -------------------------------- ### Example Release Repository Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/releaserepo.md This is an example of how to specify a single repository named 'cnf' for releases. ```properties -releaserepo=cnf ``` -------------------------------- ### Execute Macros on Project Initialization Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/init.md Use the -init instruction to list macros that should always run during project initialization. This ensures setup steps are completed before the build starts. ```bnd -init: ${my_macro}, ${my_macro2} ``` -------------------------------- ### Example -buildrepo Usage Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/buildrepo.md This example shows how to specify a single repository named 'Local' for releasing built JARs. ```bnd -buildrepo=Local ``` -------------------------------- ### Example -executable Instruction Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/executable.md This example demonstrates the basic usage of the -executable instruction with rejar and strip directives. ```bnd -executable: rejar=STORE,strip=*:OSGI-OPT/* ``` -------------------------------- ### Example -donotcopy Usage Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/donotcopy.md An example demonstrating how to use the -donotcopy instruction with a specific regular expression to exclude files. ```bnd -donotcopy=(CVS|\.svn) ``` -------------------------------- ### Example Maven Settings XML Source: https://github.com/bndtools/bnd/blob/master/docs/_commands/_ext/maven.md An example of a Maven settings.xml file, often used to configure repositories, servers, and profiles for Maven builds. This example shows configuration for a Nexus mirror. ```xml deploymentRepo deployment deployment123 nexus * https://svn.myfarm365.de/nexus/content/groups/public /Users/aqute/Desktop/Peter_Kriens.p12 nexus central http://central true always true always http://central central true always true always nexus ``` -------------------------------- ### Install Bnd CLI Source: https://github.com/bndtools/bnd/blob/master/docs/_layouts/bnd-legacy-front.html Installs the bnd CLI by downloading the JAR and creating a shell alias for easy use. Verifies installation by displaying the bnd version. ```shell # Install bnd CLI (precondition for the other examples) curl -Lk -o ~/biz.aQute.bnd.jar https://bndtools.jfrog.io/artifactory/update-latest/biz/aQute/bnd/biz.aQute.bnd/{{ site.data.bnd_version.baseline_version }}/biz.aQute.bnd-{{ site.data.bnd_version.baseline_version }}.jar # create alias for easy use via 'bnd' alias bnd='java -jar ~/biz.aQute.bnd.jar' # display bnd version to verify installation bnd version ``` -------------------------------- ### Bnd Manifest Output Example Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/125-tour-features.md Example of the manifest content displayed by the 'bnd [bundle-jar]' command. ```text [MANIFEST javax.activation] Bnd-LastModified 1407229057278 Bundle-ManifestVersion 2 Bundle-Name javax.activation Bundle-SymbolicName javax.activation Bundle-Version 0 Created-By 1.8.0 (Oracle Corporation) Export-Package com.sun.activation.registries;version="0.0.0", com.sun.activation.viewers;uses:="javax.activation";version="0.0.0", javax.activation;version="0.0.0" Manifest-Version 1.0 Require-Capability osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.4))" Tool Bnd-2.4.0.201408050759 ``` -------------------------------- ### Example Bundle-Category Value Source: https://github.com/bndtools/bnd/blob/master/docs/_heads/bundle_category.md A simple example of setting the Bundle-Category header with a single category. ```text Bundle-Category: test ``` -------------------------------- ### BND Remote Start Command Source: https://github.com/bndtools/bnd/blob/master/docs/_commands/remote.md Starts specified bundles on the remote framework. ```APIDOC ## remote start ### Description Communicate with the remote framework to perform bundle operation ### Synopsis: start ``` -------------------------------- ### Bundle-Developers Example Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/pom.md Example of the Bundle-Developers header format for specifying developer information. ```properties Bundle-Developers: \ Peter.Kriens@aQute.biz; \ name="Peter Kriens"; \ organization=aQute; \ roles="programmer,gopher" ``` -------------------------------- ### Install bnd CLI using curl Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/120-install.md Installs the bnd command-line interface by downloading the executable JAR. It's recommended to create an alias for easier use. Verify the installation by checking the version. ```bash # Install bnd CLI curl -Lk -o ~/biz.aQute.bnd.jar \ https://bndtools.jfrog.io/artifactory/update-latest/biz/aQute/bnd/biz.aQute.bnd/{{ site.data.bnd_version.baseline_version }}/biz.aQute.bnd-{{ site.data.bnd_version.baseline_version }}.jar # create alias for easy use via 'bnd' alias bnd='java -jar ~/biz.aQute.bnd.jar' # display bnd version to verify installation bnd version # Run commands bnd # Example bnd help ``` -------------------------------- ### Install Build Tool with bnd CLI Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/buildtool.md Execute the `bnd buildtool` command to download and install the specified build tool into the workspace. The `--force` flag can be used to overwrite existing installations. ```bash $ bnd buildtool --force ``` -------------------------------- ### Example -plugin Instruction Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/plugin.md Demonstrates a basic usage of the -plugin instruction with a class name and a parameter. ```properties -plugin=aQute.lib.spring.SpringComponent,aQute.lib.deployer.FileRepo;location=${repo} ``` -------------------------------- ### OSGi Provide-Capability Header Example Source: https://github.com/bndtools/bnd/blob/master/docs/_heads/_ext/provide_capability.md This is an example of the Provide-Capability header in OSGi, specifying a service with its object class and version. ```osgi Provide-Capability: osgi.service;objectClass=com.example.MyService;version=1.0.0 ``` -------------------------------- ### Create Launchpad with Framework Bundles and Register Service Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/315-launchpad-testing.md Create a Launchpad instance with necessary framework bundles (log, scr, configadmin), register a mock 'Bar' service, and assert that the component using it is activated. ```java @Test public void component() throws Exception { Bundle b = launchpad.component(C.class); AtomicBoolean called = new AtomicBoolean(false); launchpad.register(Bar.class, ()-> called.set(true) ); assertThat(called.get()).isTrue(); } ``` -------------------------------- ### Include Resources Example Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/includeresource.md Demonstrates the syntax for including resources, including a JAR file, a specific file, and a class file from a specific source path. ```bnd Include-Resource: @osgi.jar,[=\ =] {LICENSE.txt},[=\ =] acme/Merge.class=src/acme/Merge.class ``` -------------------------------- ### bnd Run Configuration Example Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/150-build.md Configure VM options, classpath, system packages, properties, and bundles for launching an OSGi framework. Use -runtrace for debugging. ```bnd -runvm: -Xmn100M, -Xms500M, -Xmx500M -runpath: \ org.apache.felix.framework; version=3.0, \ junit.osgi;export="junit.framework;version=3.8" -runtrace: true -runproperties: launch=42, trace.xyz=true -runbundles: org.apache.felix.configadmin,\ org.apache.felix.log,\ org.apache.felix.scr,\ org.apache.felix.http.jetty,\ org.apache.felix.metatype,\ org.apache.felix.webconsole ``` -------------------------------- ### Example -jpms-module-info Instruction Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/jpms_module_info.md An example demonstrating how to use the -jpms-module-info instruction with a module name, version, and specific access flags. ```plaintext -jpms-module-info: foo.module;version=5.4.1; access="OPEN,SYNTHETIC" ``` -------------------------------- ### Find plugins and convert to run requirements Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/findproviders.md This example shows how to use `findproviders` to locate plugins with a specific `osgi.service` capability and an LDAP filter, then uses the `template` macro to convert them into `-runrequires` entries. ```bnd my.plugins = ${findproviders;osgi.service;\ (objectClass=com.example.my.Plugin)} -runrequires.plugins = ${template;my.plugins;\ osgi.identity;filter:='(osgi.identity=${@})'} ``` -------------------------------- ### Variable Expansion Example Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/00-overview.md Demonstrates basic variable expansion for bundle version and description. Ensure variables are defined before use. ```properties version=1.23.87.200109111023542 Bundle-Version= ${version} Bundle-Description= This bundle has version ${version} ``` -------------------------------- ### Example of Expanded gradle.properties Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/buildtool.md After installation, properties defined in the workspace's `-buildtool` instruction are appended to relevant files in the template, such as `gradle.properties`. This example shows how bnd-specific variables are integrated. ```properties # Appended by tool manager at 2021-12-02T14:40:55.660843Z version = url bnd_version = 6.1.0 bnd_snapshots = https://bndtools.jfrog.io/bndtools/libs-snapshot-local ``` -------------------------------- ### Get all repository names Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/repos.md This macro returns a comma-separated string of all configured repository names. The output is an example and may vary based on your configuration. ```bnd ${repos} # Returns: "Maven Central, Local, Workspace, Release" (example) ``` -------------------------------- ### Example -sub instruction with specific pattern Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/sub.md Shows a specific pattern for the -sub instruction, targeting files starting with 'com.acme.' and ending with '.bnd'. ```bnd -sub=com.acme.*.bnd ``` -------------------------------- ### Get Bundle-Version syntax Source: https://github.com/bndtools/bnd/blob/master/docs/_commands/syntax.md Use the syntax command to retrieve information about the 'Bundle-Version' header. This header specifies the version of a bundle and has a defined pattern and examples. ```bash biz.aQute.bnd (master)$ bnd syntax Bundle-Version [Bundle-Version] The Bundle-Version header specifies the version of this bundle. Pattern : [0-9]{1,9}(\.[0-9]{1,9}(\.[0-9]{1,9}(\.[0-9A-Za-z_-]+)?)?)? Example : Bundle-Version: 1.23.4.build200903221000 ``` -------------------------------- ### Extract first 5 characters using substring macro Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/substring.md Use the substring macro with start and end indices to get a prefix of a string. The end index is exclusive. ```bnd ${substring;hello world;0;5} # Returns: "hello" ``` -------------------------------- ### Assign Start Level and Order Bundles Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/runstartlevel.md Sets the start level calculation to begin at 1, with a step of 1, and orders bundles by least dependencies first. ```properties -runstartlevel: '-runstartlevel order=leastdependenciesfirst, begin=1, step=1 ``` -------------------------------- ### Example Build Dependency Path Source: https://github.com/bndtools/bnd/blob/master/docs/_heads/.bnd.md Illustrates the expected format for versioned build dependency JAR files within the build-deps directory. ```text ~/.bnd/biz.aQute.bnd-2.2.0.jar ``` -------------------------------- ### Compile TypeScript with -prepare Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/prepare.md Example of using the -prepare instruction to compile TypeScript files. Ensure the 'tsc' command is installed via npm. The output is directed to 'web/repository.js'. ```bnd -prepare:\ web/foo.js <= typescript/*.ts ; \ command:=tsc -p typescript --out $@ ``` -------------------------------- ### Baseline bundles matching a pattern Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/baseline.md Use this instruction to baseline any bundle whose symbolic name matches the provided pattern. This example baselines bundles starting with 'com.example.'. ```java -baseline: com.example.* ``` -------------------------------- ### Initialize LaunchpadBuilder Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/315-launchpad-testing.md Create a `LaunchpadBuilder` instance to configure the OSGi framework. The builder stores settings and does not need to be closed. ```java LaunchpadBuilder builder = new LaunchpadBuilder() .runfw("org.apache.felix.framework"); ``` -------------------------------- ### Remove Manifest Headers with Selectors Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/125-tour-features.md Remove headers from the manifest using a selector expression. The example removes headers starting with 'Bundle-' except for 'Bundle-Name', with a case-insensitive match for 'Bundle-Name'. ```properties -removeheaders: !Bundle-*, Bundle-Name:i ``` -------------------------------- ### Define Aspect with Annotation Model Source: https://github.com/bndtools/bnd/blob/master/docs/_plugins/aspectj.md Define an aspect using AspectJ's annotation model in a Java bundle. This example shows how to intercept the start method of an OSGi Bundle Activator. ```java @Aspect public class AspectHandler { @Before("execution(void *.start(org.osgi.framework.BundleContext))") public void myadvice(JoinPoint jp) { BundleContext c = (BundleContext) jp.getArgs()[0]; System.out.println("Starting bundle : " + c.getBundle()); } } ``` -------------------------------- ### Execute Gradle Build Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/buildtool.md Once the build tool is installed via bnd, it can be executed directly from the workspace root. This example shows how to run a Gradle clean build with parallel execution enabled. ```bash $ ./gradlew --parallel clean build ``` -------------------------------- ### Create a WAB/WAR with static pages and libraries Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/wab.md This configuration extends the previous example by including JAR files from the 'lib/' directory into the WEB-INF/lib folder. These JARs are automatically added to the Bundle-Classpath, allowing them to be used by the WAB. ```bnd Private-Package: com.example.impl.* Export-Package: com.example.service.myapi Include-Resource: resources/ -wab: static-pages/ -wablib: lib/a.jar, lib/b.jar ``` -------------------------------- ### Get First Defined Version Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/first.md This example shows how to use the 'first' macro to obtain the first defined version from a sequence of potential version properties. It's effective for implementing fallback logic. ```bnd version=${first;${custom.version};${default.version};1.0.0} ``` -------------------------------- ### Example of -generate with system command Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/generate.md Illustrates using the 'system' option to execute a command for code generation. The command is executed relative to the project directory. ```bnd -generate "src/main/java;output=generated-sources;clear=true;system=echo 'Hello World' > generated.txt" ``` -------------------------------- ### Example of Merged Instruction: -buildpath Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/00-overview.md Demonstrates how -buildpath and -buildpath.extra combine to form a final buildpath, conditionally including a debug version. ```bnd -buildpath: com.example.foo;version=1.2 -buildpath.extra: ${if;${debug};com.example.foo.debug\;version=1.2} ``` -------------------------------- ### Remove Specific Headers from Manifest Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/removeheaders.md Use -removeheaders to exclude headers matching the provided names or patterns from the bundle manifest. Example shows removing headers starting with 'FOO_' and the 'Proprietary' header. ```bnd -removeheaders=FOO_.*,Proprietary ``` -------------------------------- ### Import Package with Custom Version Range Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/consumer_policy.md Overrides the default consumer policy for a specific import. This example uses the range macro to define a custom version range for packages starting with 'com.gavinking.*'. ```bnd Import-Package com.gavinking.*;version="${range;[--,++)}", * ``` -------------------------------- ### Get Last Path Component using findlast Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/findlast.md This example shows how to extract the last component of a path using the findlast and substring macros. It locates the last forward slash (/) and extracts the substring following it. ```bnd ${substring;${path};${findlast;/;${path}}} ``` -------------------------------- ### Exclude and Import All Packages Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/920-faq.md This configuration excludes all packages starting with 'com.example' and then imports all others. If 'com.example.*' is too broad, it can result in no imports. ```bnd Import-Package: !com.example.*, * ``` -------------------------------- ### Get Target Bytecode Version Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/ide.md Retrieves the Java target bytecode version configured in Eclipse IDE preferences. Example values include "1.8", "11", or "17". ```java javac.target=${ide;javac.target} ``` -------------------------------- ### Complex example with attributes and merging Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/list.md This example demonstrates merging base dependencies with extra dependencies, both of which include version attributes. The output is suitable for build path configurations. ```bnd -buildpath: ${list;base-deps;extra-deps} ``` -------------------------------- ### Track Build Input Modification Times Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/fmodified.md This example shows how to track the modification times of all files in the build path. It uses the `buildpath` macro to get the list of files and `fmodified` to determine the latest modification timestamp among them. ```bnd Build-Input-Modified: ${fmodified;${buildpath}} ``` -------------------------------- ### Start Local OSGi Framework with Bnd Bootstrap Source: https://github.com/bndtools/bnd/blob/master/docs/_commands/_ext/bootstrap.md Use this command to launch a local OSGi framework using your workspace's configuration. Ensure the bnd.bnd file exists in the cnf directory. ```bash bnd bootstrap ``` -------------------------------- ### Check if Source Files Changed Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/fmodified.md This example demonstrates how to check if source files have changed by comparing their modification times. It uses the `lsr` macro to find Java files in the 'src' directory and then `fmodified` to get their latest modification timestamp. ```bnd source.modified=${fmodified;${lsr;src;*.java}} ``` -------------------------------- ### Basic -runrequires Example Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/runrequires.md Specifies requirements for specific OSGi identities and version ranges. Use this for direct OSGi capability matching. ```bnd -runrequires: \ osgi.identity; filter:='(osgi.identity=org.example.foo)',\ osgi.identity; filter:='(&(osgi.identity=org.example.bar)(version>=1.0)(!(version>=2.0)))' ``` -------------------------------- ### Tool.bnd Instruction for File Processing Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/buildtool.md This is an example of a tool.bnd file found within a build tool template zip. It defines how files from the template archive should be processed during installation, specifying skipping, macro expansion, appending attributes, and executable permissions. ```properties -tool \ .*;tool.bnd;skip=true, \ gradle.properties;macro=true,\ gradlew;exec=true, \ * ``` -------------------------------- ### Include Specific Package and Sub-packages Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/conditionalpackage.md This example shows how to include a specific package ('mypackage.example') and all its sub-packages if they are referenced by the current JAR's contents. These packages will be copied into the bundle as private resources. ```bnd -conditionalpackage: mypackage.example.* ``` -------------------------------- ### Set Initial Start Level Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/runstartlevel.md Specifies the starting start level for bundle assignment. A value of -1 indicates no automatic calculation. ```properties begin='begin=10 ``` -------------------------------- ### Define Run Start Level Configuration Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/runstartlevel.md Use this configuration to define the order, starting level, and step for resolving run bundles. This sets up the initial conditions for bundle startup. ```bnd -runstartlevel: \ order = leastdependenciesfirst, \ begin = 1000, \ step = 1 ``` -------------------------------- ### Specify Bundles with Start Levels Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/runbundles.md When using launchers that support start levels, you can assign a start level to each bundle listed in -runbundles. The start level must be a positive integer greater than 0. Note that these settings may be overridden by the resolver. ```properties -runbundles: \ org.apache.felix.configadmin;version='[1.8.8,1.8.9)'; startlevel=100, org.apache.felix.http.jetty;version='[3.2.0,3.2.1)'; startlevel=110, ... ``` -------------------------------- ### Set Start Level Step Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/runstartlevel.md Defines the increment between start levels for consecutive bundles. A value less than 1 results in a start level of 0. ```properties step='begin=1 ``` -------------------------------- ### Create Bnd Workspace and Launch Application Source: https://github.com/bndtools/bnd/blob/master/docs/_layouts/bnd-legacy-front.html Demonstrates creating a new bnd workspace using templates and launching a development server for live-coding. Requires bnd 7.2.0 or later. ```shell # Create a new workspace with templates bnd add workspace -f demo-webapp -f osgi myworkspace # Navigate to the workspace cd myworkspace # Start a live-coding / hot reload dev server to run the application during development in an editor bnd dev launch.bndrun # or alternatively just build and run the application without hot-reloading: bnd build ``` -------------------------------- ### Register and Verify Service Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/315-launchpad-testing.md Demonstrates registering a service with the Launchpad, waiting for it to become available, and then verifying its presence. The service is then unregistered, and its absence is confirmed. ```java interface Foo {} @Test public void services() throws Exception { try (Launchpad launchpad = builder.create()) { ServiceRegistration register = launchpad.register(Foo.class, new Foo() {}); Optional s = launchpad.waitForService(Foo.class, 100); assertThat(s.isPresent()).isTrue(); register.unregister(); s = launchpad.waitForService(Foo.class, 100); assertThat(s.isPresent()).isFalse(); } } ``` -------------------------------- ### Find all resources with osgi.service capability Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/findproviders.md This example demonstrates how to find all resources that have an `osgi.service` capability. No filter is applied, so all matching resources are returned. ```bnd ${findproviders;osgi.service} ``` -------------------------------- ### GET /get Source: https://github.com/bndtools/bnd/blob/master/biz.aQute.http.testservers/src/aQute/http/testservers/www/default.html Returns GET data received by the server. ```APIDOC ## GET /get ### Description Returns GET data received by the server, including arguments, headers, and origin IP. ### Method GET ### Endpoint /get ### Response #### Success Response (200) - **args** (object) - URL query parameters. - **headers** (object) - Request headers. - **origin** (string) - The IP address of the client. - **url** (string) - The requested URL. #### Response Example ```json { "args": { "param1": "value1" }, "headers": { "Host": "httpbin.org" }, "origin": "192.0.2.1", "url": "http://httpbin.org/get?param1=value1" } ``` ``` -------------------------------- ### Bundle-Contributors Header Example Source: https://github.com/bndtools/bnd/blob/master/docs/_heads/_ext/bundle_contributors.md This is an example of how the Bundle-Contributors header might look. ```text Bundle-Contributors: John Doe;roles='developer';organization='Example Corp.' ``` -------------------------------- ### Create and Run Launchpad Test Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/315-launchpad-testing.md Use a try-with-resources block to create and launch the OSGi framework with Launchpad, inject services, and shut down the framework upon closing. ```java @Test public void quickStart() throws Exception { try (Launchpad launchpad = builder.create() .inject(this)) { assertNotNull(context); } } ``` -------------------------------- ### Add Launchpad to Test Path Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/315-launchpad-testing.md Ensure the `biz.aQute.launchpad` library is available on your `-testpath` in the `bnd.bnd` file. ```bnd -testpath: \ osgi.enroute.junit.wrapper, \ biz.aQute.launchpad ``` -------------------------------- ### BND Remote Install Command Source: https://github.com/bndtools/bnd/blob/master/docs/_commands/remote.md Installs or updates bundles on the remote framework. ```APIDOC ## remote install ### Description Communicate with the remote framework to install or update bundle ### Synopsis: install [options] ##### Options: - `[ -l --location ]` By default the location is 'manual:'. You can specify multiple locations when installing multiple bundles ``` -------------------------------- ### Example Baselining Project Instructions Source: https://github.com/bndtools/bnd/blob/master/docs/_chapters/180-baselining.md This example configures baselining to use the last version in the 'Released' repository as the baseline. Ensure staging versions are not consistently released to this repository to avoid false changes. ```properties Bundle-Version: 1.0.2 -baseline: * -baselinerepo: Released ``` -------------------------------- ### Example -reportnewer Usage Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/reportnewer.md This shows an example of how to set the -reportnewer instruction to true. ```bnd -reportnewer=true ``` -------------------------------- ### Basic -includeresource example Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/includeresource.md Includes a JAR file, a specific text file, and a literal string as resources. The literal string is set to 'true'. ```bnd -includeresource: lib/=jar/, {preprocess.txt}, 'literal';literal;=true, ``` -------------------------------- ### Serve Documentation Locally with Docker Source: https://github.com/bndtools/bnd/blob/master/docs/Agents.md Use Docker to run a Jekyll development server for local documentation preview. This command mounts the current directory and exposes the server on port 4000. ```bash docker run --rm -it -p 4000:4000 -v "$PWD":/srv/jekyll -w /srv/jekyll jekyll/jekyll:4 jekyll serve -w --incremental --host 0.0.0.0 ``` -------------------------------- ### Quickstart Mill OSGi Plugin Configuration Source: https://github.com/bndtools/bnd/blob/master/docs/_tools/mill-osgi.md This snippet demonstrates how to load and use the mill-osgi plugin in a Mill build. It shows how to define the bundle symbolic name and configure OSGi headers like Export-Package and Bundle-Activator. ```scala // mill default imports import mill._, scalalib._ // Load mill-osgi in version 0.2.0 import $ivy.`de.tototec::de.tobiasroeser.mill.osgi:0.2.0` // and import its main package import de.tobiasroeser.mill.osgi._ object project extends JavaModule with OsgiBundleModule { def bundleSymbolicName = "com.example.project" def osgiHeaders = T{ osgiHeaders().copy( `Export-Package` = Seq("com.example.api"), `Bundle-Activator` = Some("com.example.internal.Activator") )} } ``` -------------------------------- ### DynamicImport-Package Example Source: https://github.com/bndtools/bnd/blob/master/docs/_heads/_ext/dynamicimport_package.md Example of the DynamicImport-Package header syntax, listing packages with wildcards. ```java DynamicImport-Package: com.example.*, org.osgi.service.* ``` -------------------------------- ### Multiple attributes and instructions Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/_ext/jpms_module_info_options.md Example demonstrating the use of multiple attributes and instructions for module-info.class generation. ```properties -jpms-module-info-options: \ java.enterprise;substitute="geronimo-jcdi_2.0_spec";static=true;transitive=true, java.management;ignore=true; ``` -------------------------------- ### Build Path Decoration Example Source: https://github.com/bndtools/bnd/blob/master/docs/_macros/decorated.md Demonstrates decorating build path dependencies. This allows applying specific version constraints or other attributes to dependencies based on defined patterns, particularly useful for test dependencies. ```bnd # Build path decoration -buildpath = commons-io, commons-lang -buildpath.test = junit, mockito -buildpath+ = junit;version=4.12, mockito;version=2.0 ${decorated;-buildpath} # Test dependencies get specific versions ``` -------------------------------- ### Example of Decorated Instruction: -runbundles Source: https://github.com/bndtools/bnd/blob/master/docs/_instructions/00-overview.md Shows how a decorator '-runbundles+ *;startlevel=20' adds a startlevel attribute to entries in the '-runbundles' instruction. ```bnd -runbundles a -runbundles+ *;startlevel=20 ``` -------------------------------- ### DynamicImport-Package Example Source: https://github.com/bndtools/bnd/blob/master/docs/_heads/dynamicimport_package.md Example of the DynamicImport-Package header with a wildcard to import all classes from a specific package. ```properties DynamicImport-Package: com.acme.plugin.* ```