Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Convert maven-bundle-plugin to bnd-maven-plugin for new archetypes

Avatar

Level 4

Hi I am using Old archetype which is using maven-bundle-plugin as below.

 

I want to convert this into bnd-maven-plugin which is part of new archetype .How to convert Import packages,Export Packages and embed dependency for bnd-maven-plugin.we are getting error 

in start level 20 but no bundle is exporting these for that start level on running aem-analyzer plugin

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
 
<instructions>
<!-- Import any version of javax.inject and javax.annotation, to allow
running on multiple versions of AEM -->
<Import-Package>
!org.codehaus.groovy.*,
javax.inject;version=0.0.0,
javax.annotation;version=0.0.0,
!org.bouncycastle.*,
!javax.cache.*
</Import-Package>
<Export-Package>
com.akamai.edgegrid.signer.*
</Export-Package>
<Embed-Dependency>
flying-saucer-core,
flying-saucer-pdf,
jsoup,
javaslang;scope=compile,javaslang-jackson;scope=compile|runtime
</Embed-Dependency>
</instructions>
</configuration>
</dependencies>
</plugin>
 
4 Replies

Avatar

Level 10

Avatar

Level 4

Hi @giuseppebag ,

Thanks for the reply.

What to use in case of Embed Dependency or if we want to use Third Party jar to add it in the OSGI bundle.

The above example provide some hint but not 100% sure how we can use for my Use case.

Avatar

Community Advisor

Hi @Sb2512 ,

Try below solution:

1. Replace maven-bundle-plugin with bnd-maven-plugin

In your pom.xml:

<plugin>
  <groupId>biz.aQute.bnd</groupId>
  <artifactId>bnd-maven-plugin</artifactId>
  <version>6.4.0</version> <!-- or latest -->
  <executions>
    <execution>
      <goals>
        <goal>bnd-process</goal>
      </goals>
    </execution>
  </executions>
</plugin>

2. Add bnd.bnd file in the same module (typically under /core)

Create a bnd.bnd file (in the same directory as your pom.xml) with the following content:

Bundle-Name: My Bundle
Bundle-SymbolicName: com.mycompany.core
Bundle-Version: 1.0.0

# Import Packages
Import-Package: \
  !org.codehaus.groovy.*,\
  javax.inject;version=0.0.0,\
  javax.annotation;version=0.0.0,\
  !org.bouncycastle.*,\
  !javax.cache.*,\
  *

# Export Packages
Export-Package: \
  com.akamai.edgegrid.signer.*

# Embedded Dependencies (include-dependency is bnd syntax)
-includeresource: \
  @flying-saucer-core.jar,\
  @flying-saucer-pdf.jar,\
  @jsoup.jar,\
  @javaslang.jar,\
  @javaslang-jackson.jar

# Make sure they are included from dependencies
-runbundles: \
  flying-saucer-core,\
  flying-saucer-pdf,\
  jsoup,\
  javaslang,\
  javaslang-jackson

3. Add the dependencies in pom.xml

Make sure the JARs to embed are added as dependencies with scope=compile:

<dependencies>
  <dependency>
    <groupId>org.jsoup</groupId>
    <artifactId>jsoup</artifactId>
    <version>1.13.1</version>
  </dependency>
  <dependency>
    <groupId>org.xhtmlrenderer</groupId>
    <artifactId>flying-saucer-core</artifactId>
    <version>9.1.20</version>
  </dependency>
  <dependency>
    <groupId>org.xhtmlrenderer</groupId>
    <artifactId>flying-saucer-pdf</artifactId>
    <version>9.1.20</version>
  </dependency>
  <dependency>
    <groupId>io.vavr</groupId>
    <artifactId>vavr</artifactId>
    <version>0.10.3</version>
  </dependency>
  <dependency>
    <groupId>io.vavr</groupId>
    <artifactId>vavr-jackson</artifactId>
    <version>0.10.3</version>
  </dependency>
</dependencies>

4. Embed JARs in the OSGi bundle using bnd-maven-plugin

Ensure the bnd.bnd file points to where the dependencies are built (they must be in your local Maven repo or project build path).

You can also use -buildpath or configure -includeresource with ${@} to automate:

-includeresource: @${@}

But most commonly, just use @jar-name.jar or Maven coordinates if scripting with BND workspace.

 

Build your bundle:

mvn clean install

Then use:

unzip -l target/yourbundle.jar

You’ll see embedded JARs inside the bundle, and exports will reflect only what you declared.

Note:

Don't forget to remove maven-bundle-plugin from the old pom.xml.

The bnd.bnd file must reside in the same module as the bundle you're building.

The dependencies are pulled from the build path, so Maven must resolve them correctly.

Regards,
Amit

Avatar

Administrator

@Sb2512 

Just checking in — were you able to resolve your issue?
We’d love to hear how things worked out. If the suggestions above helped, marking a response as correct can guide others with similar questions. And if you found another solution, feel free to share it — your insights could really benefit the community. Thanks again for being part of the conversation!



Kautuk Sahni