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
Solved! Go to Solution.
Views
Replies
Total Likes
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.
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
Views
Replies
Total Likes
Views
Replies
Total Likes
Check if you have * (import or export all the packages) inside <Export-Package> and <Import-Package> elements
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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>
Views
Replies
Total Likes
Views
Likes
Replies
Views
Like
Replies