How to resolve custom bundle A dependency on bundle B | Community
Skip to main content
July 2, 2020
Solved

How to resolve custom bundle A dependency on bundle B

  • July 2, 2020
  • 2 replies
  • 5464 views

Hi Team, I have created custom service interface a in bundle A  and i need to call this interface - a service in my other custom bundle service .can we directly do it using reference annotation after deploying bundle A in osgi Felix console or need to do other way .                                                                                                            Hi All, thanks for your help.today I have used a service from different bundle to my bundle servlet class...and I have not exported and imported any service in pom of core .but I have added a dependency of the different bundle class in my bundles pom.xml and it shows automatically in system consolle manifiest details that service is imported. I need to check you that I only added maven dependency in my bundle pom which I got from dependency finder from console. Does we not need to do any import export for this?? Kindly reply team plz 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by BrianKasingli

@ashutot1,

Firstly, let's explore the definition of a bundle export vs bundle import. A bundle export exports a package to make the corresponding programs and resources available for use by other bundles. A bundle import, imports a package to use the corresponding programs and resources of another bundle.

 

Now to the question:

Your Bundle-A should export the package with the service interface as so:

 

<Export-Package>com.bundle.a</Export-Package>

 

 

Your bundle B should import the package as so:

 

<Import-Package>com.bundle.a;version=1.0.0</Import-Package>

 

 

However, when you are creating a new AEM project using the AEM Project Archetype, all the default imports configuration is to import all bundles to make available for the project's bundle, like so:

 

<Import-Package>javax.inject;version=0.0.0,*</Import-Package>

 

I hope this helps.

 

2 replies

Community Advisor
July 2, 2020

You should export the required packages from source bundle(Export-Package) and import the packages(Import-Package) into the target bundle

The configurations can be enabled through the core module Pom.xml(enable the configurations based on the plug in used)

For maven-bundle-plugin

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>org.foo.myproject.api.*</Export-Package>
<Bundle-Activator>org.foo.myproject.impl1.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>javax.annotation;version=0.0.0,*</Export-Package>
<Bundle-Activator>org.foo.myproject.impl1.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>

For bnd-maven-plugin

<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<executions>
<execution>
<id>bnd-process</id>
<goals>
<goal>bnd-process</goal>
</goals>
<configuration>
<bnd><![CDATA[
Import-Package: javax.annotation;version=0.0.0,*
]]></bnd>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<executions>
<execution>
<id>bnd-process</id>
<goals>
<goal>bnd-process</goal>
</goals>
<configuration>
<bnd><![CDATA[
Export-Package: org.foo.myproject.api.*
]]></bnd>
</configuration>
</execution>
</executions>
</plugin>

 

Regards

Albin I

www.albinsblog.com

ashutot1Author
July 3, 2020
Hi Alb, thankful to you.i just have one general query here ..why we are using two plugin one is maven bundle plugin but what is the provision of bnd plugin can we do this export import without bnd please
BrianKasingli
Community Advisor and Adobe Champion
BrianKasingliCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
July 2, 2020

@ashutot1,

Firstly, let's explore the definition of a bundle export vs bundle import. A bundle export exports a package to make the corresponding programs and resources available for use by other bundles. A bundle import, imports a package to use the corresponding programs and resources of another bundle.

 

Now to the question:

Your Bundle-A should export the package with the service interface as so:

 

<Export-Package>com.bundle.a</Export-Package>

 

 

Your bundle B should import the package as so:

 

<Import-Package>com.bundle.a;version=1.0.0</Import-Package>

 

 

However, when you are creating a new AEM project using the AEM Project Archetype, all the default imports configuration is to import all bundles to make available for the project's bundle, like so:

 

<Import-Package>javax.inject;version=0.0.0,*</Import-Package>

 

I hope this helps.

 

ashutot1Author
July 4, 2020
Hi brian, thanks for your help.today I have used a service from different bundle to my bundle servlet class...and I have not exported and imported any service in pom of core .but I have added a dependency of the different bundle class in my bundles pom.xml and it shows automatically in system consolle manifiest details that service is imported. I need to check you that I only added maven dependency in my bundle pom which I got from dependency finder from console. Does we not need to do any import export for this