Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

How to resolve custom bundle A dependency on bundle B

Avatar

Avatar
Validate 1
Level 2
ashutot1
Level 2

Likes

4 likes

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back
View profile

Avatar
Validate 1
Level 2
ashutot1
Level 2

Likes

4 likes

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back
View profile
ashutot1
Level 2

02-07-2020

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 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

611 likes

Total Posts

588 posts

Correct Reply

230 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

611 likes

Total Posts

588 posts

Correct Reply

230 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

02-07-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.

 

ashutot1
Hi Brian, thanks a lot for your reply.i just have one query that this import and export we need to manually add to our parent pom.xml after archetype project creation ?? Or some default import export tags added in pom
BrianKasingli

It will not be in the parent pom, but it will in your core's pom. Using the Maven Archetype as an example, the core bundle will be generated as apart of the generation of a new AEM project. The generated pom.xml from the core bundle may look like something like this:

 

<plugin>
     <groupId>org.apache.felix</groupId>
     <artifactId>maven-bundle-plugin</artifactId>
     <extensions>true</extensions>
     ...
     <configuration>
          <exportScr>true</exportScr>
          <instructions>
               <Build-Time>${timestamp}</Build-Time>
               <Build-Number>${buildNumber}</Build-Number>
               <!--suppress UnresolvedMavenProperty -->
               <Build-Branch>${scmBranch}</Build-Branch>
               <!-- Import any version of javax.inject, to allow running on multiple versions of AEM -->
               <Import-Package>javax.inject;version=0.0.0,*</Import-Package>
               ...
          </instructions>
     </configuration>
</plugin>

 

 

ashutot1
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

Answers (1)

Answers (1)

Avatar

Avatar
Validate 1
MVP
Albin_Issac
MVP

Likes

106 likes

Total Posts

119 posts

Correct Reply

33 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Validate 1
MVP
Albin_Issac
MVP

Likes

106 likes

Total Posts

119 posts

Correct Reply

33 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Albin_Issac
MVP

02-07-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