Expand my Community achievements bar.

SOLVED

Difficulty on activating an osgi bundle

Avatar

Level 6

I am building an OSGI Bundle in Eclipse then importing it into AEM. I cannot get the imported package com.headwire.cqblueprints.examples.osgi to be loaded with        mvn -PautoInstallBundle clean install.

 

If I use mvn -PautoInstallBundle clean install -X I do not get any errors and the jar file is created.

 

In http://localhost:4502/system/console/bundles/331

I get

                                 
Symbolic NameShoprite.Nigeria.Services.Shoprite.Nigeria.Services-bundle
Version1.0.0.SNAPSHOT
Bundle Locationinputstream:Shoprite.Nigeria.Services-bundle-1.0-SNAPSHOT.jar
Last ModificationThu Sep 04 13:01:07 CAT 2014
DescriptionMaven Multimodule project for Services.
Start Level20
Exported PackagesShoprite.Nigeria.Models,version=1.0.0
Shoprite.Nigeria.Services,version=1.0.0
Imported Packagescom.headwire.cqblueprints.examples.osgi -- Cannot be resolved
javax.net.ssl from org.apache.felix.framework (0)
javax.xml.parsers from org.apache.felix.framework (0)
org.slf4j,version=[1.5,2) from slf4j.api (14)
1 Accepted Solution

Avatar

Correct answer by
Level 10

You need to create a bundle fragment with that Java library and deploy. This red means that AEM cannot find the dependency. One way you can resolve this issue is to get a JAR with this Java API in it and use Eclipse Plug-in project to wrap that JAR into an AEM bundle. Then deploy the OSGi bundle to AEM. This will eliminate the dependency issue. We have an example of wrapping the SIMPLE JSON JAR in this community article:

http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

View solution in original post

8 Replies

Avatar

Level 6

It seems that you have not uploaded bundle into Felix console which contains the class com.headwire.cqblueprints.examples.osgi 

Avatar

Community Advisor

Or if the bundle is present in your OSGI container then it doesn't expose the desired package via its manifest file.

To see whether any of the bundle output the desired package; use the dependency finder console of Felix - http://localhost:4502/system/console/depfinder

put the package declaration and click on find. It will give you the information about bundle present in your OSGI that exposes the provided package.

- Runal

Avatar

Level 6

The dependency comes from the foillowing part of my pom

                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <configuration>
                        <instructions>
                            <Bundle-Activator>com.headwire.cqblueprints.examples.osgi.Activator</Bundle-Activator>
                            <Private-Package>com.headwire.cqblueprints.examples.osgi</Private-Package>
                            <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                            <Embed-Directory>OSGI-INF/lib</Embed-Directory>
                            <Embed-Transitive>true</Embed-Transitive>
                            <Import-Package>!org.slf4j.impl,*</Import-Package>
                        </instructions>
                    </configuration>
                </plugin>

 

I also point to 

 

                <repository>
                    <id>cqblueprints</id>
                    <name>blueprints Repository</name>
                    <url>http://dev.cqblueprints.com/nexus/content/repositories/releases/</url>
                    <layout>default</layout>
                </repository>

 

Inside of maven settings xml. for my build profile.

I would have thought that this would download and install the necessary far file.

 

I cannot find which jar file would contain the classes used by      <Private-Package>com.headwire.cqblueprints.examples.osgi</Private-Package>

Avatar

Level 6

The difficulty is that the felic console dependency finder cannot find  com.headwire.cqblueprints.examples.osgi 

Avatar

Community Advisor

I guess the POM Entries that you have mentioned are from your project POM file?

Also I see com.headwire.cqblueprints.examples.osgi is declared as private package, any specific reason?

Below is what you can do:

1 - Embed the jar exposing headwire.cqblueprints into your Project Bundle:

  • Since you have mentioned that while building the code you are not facing the issues and only while deploying the bundle is not getting activated, can you then check whether the compiled bundle.jar contains the headwire cqblueprint jar embedded in it?
    • This should get embedded since you have embed related tags in sling bundle plugin declaration.
  • The issue is for sure you project bundle is not able to get reference of com.headwire.cqblueprints.examples.osgi at runtime.
  • If the jar exposing com.headwire.cqblueprints.examples.osgi is getting embedded then I guess you don't need to have it in import package declaration of your project pom.

2 - Convert the jar exposing com.headwire.cqblueprints.examples.osgi into OSGI bundle if it is not already an OSGI bundle jar.

If jar exposing com.headwire.cqblueprints.examples.osgi is already an OSGI bundle jar then simply upload it in your OSGI container using http://localhost:4502/system/console/bundles and then have the package import statement in your project POM. It should work then.

-  Runal

Avatar

Level 6

I had them as private-package as i was following the example on  http://www.cqblueprints.com/tipsandtricks/build-and-deploy-osgi/build-deploy-osgi-1.html on how to  configure the Apache Felix Bundle plugin:

Avatar

Community Advisor

In the error snap that you have attached at the start, you are trying to import a package that you have declared as private package in your maven-bundle-plugin, which is <Private-Package>com.headwire.cqblueprints.examples.osgi</Private-Package>

Any package declared as private cannot be consumed by any other OSGI bundle.

If you simply looking for tutorial on how to create an OSGI bundle then following link on dev.day would help

http://dev.day.com/docs/en/cq/aem-how-tos/development/how-to-build-aem-projects-using-apache-maven.h...

More over if you want other bundles to consume files from package com.headwire.cqblueprints.examples.osgi then you need to list this package in Export-Package tag within maven-bundle-plugin.

For details on maven-bundle-plugin, refer to - http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html

- Ruanl

Avatar

Correct answer by
Level 10

You need to create a bundle fragment with that Java library and deploy. This red means that AEM cannot find the dependency. One way you can resolve this issue is to get a JAR with this Java API in it and use Eclipse Plug-in project to wrap that JAR into an AEM bundle. Then deploy the OSGi bundle to AEM. This will eliminate the dependency issue. We have an example of wrapping the SIMPLE JSON JAR in this community article:

http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html