Expand my Community achievements bar.

SOLVED

Unable to resolve bundle

Avatar

Level 4

I am getting the following error when trying to install my bundle. Other than separating my bundle in to two individual bundles. Do you have any solution?

21.11.2014 15:10:47.158 *INFO* [OsgiInstallerImpl] org.apache.sling.installer.core.impl.tasks.BundleStartTask Could not start bundle com.mycompany.aem.core-bundle [397]. Reason: {}. Will retry. org.osgi.framework.BundleException: Uses constraint violation. Unable to resolve bundle revision com.mycompany.aem.core-bundle [397.15] because it is exposed to package 'javax.inject' from bundle revisions org.apache.sling.models.api [344.0] and org.apache.sling.scripting.java [215.0] via two dependency chains. Chain 1: com.mycompany.aem.core-bundle [397.15] import: (&(osgi.wiring.package=javax.inject)(version>=0.0.0)(!(version>=1.0.0))) | export: osgi.wiring.package=javax.inject org.apache.sling.models.api [344.0] Chain 2: com.mycompany.aem.core-bundle [397.15] import: (&(osgi.wiring.package=com.google.common.cache)(version>=15.0.0)(!(version>=16.0.0))) | export: osgi.wiring.package=com.google.common.cache; uses:=javax.inject com.google.guava [78.0] import: (osgi.wiring.package=javax.inject) | export: osgi.wiring.package=javax.inject org.apache.sling.scripting.java [215.0] at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3986) at org.apache.felix.framework.Felix.startBundle(Felix.java:2043) at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976) at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:963) at org.apache.sling.installer.core.impl.tasks.BundleStartTask.execute(BundleStartTask.java:93) at org.apache.sling.installer.core.impl.OsgiInstallerImpl.executeTasks(OsgiInstallerImpl.java:733) at org.apache.sling.installer.core.impl.OsgiInstallerImpl.run(OsgiInstallerImpl.java:247) at java.lang.Thread.run(Thread.java:744)

I believe it is caused by these two dependencies as they both export Javax.inject:

<dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>15.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.models.api</artifactId> <version>1.0.0</version> </dependency>
1 Accepted Solution

Avatar

Correct answer by
Level 10

You are right - this bundle - the way it is setup has a dependency issue:

 org.apache.sling.scripting.java [215.0])
org.osgi.framework.BundleException: Uses constraint violation. Unable to resolve bundle revision com.mycompany.cq.bundle-test-bundle [394.0] because it is exposed to package 'javax.inject' from bundle revisions org.apache.sling.models.api [344.0] and org.apache.sling.scripting.java [215.0] via two dependency chains.

Chain 1:
  com.mycompany.cq.bundle-test-bundle [394.0]
    import: (&(osgi.wiring.package=javax.inject)(version>=0.0.0)(!(version>=1.0.0)))
     |
    export: osgi.wiring.package=javax.inject
  org.apache.sling.models.api [344.0]

Chain 2:
  com.mycompany.cq.bundle-test-bundle [394.0]
    import: (&(osgi.wiring.package=com.google.common.cache)(version>=15.0.0)(!(version>=16.0.0)))
     |
    export: osgi.wiring.package=com.google.common.cache; uses:=javax.inject
  com.google.guava [78.0]
    import: (osgi.wiring.package=javax.inject)
     |
    export: osgi.wiring.package=javax.inject
  org.apache.sling.scripting.java [215.0]
    at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3986)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2043)
    at org.apache.felix.framework

 

The issue here is the bundle trying to import the wrong versions of javax.inject and sling API. TO fix this issue, open the MANIFEST.MF file in the OSGi bundle using a tool like WinRAR. The path is:

slingmodel-bundle-1.0-SNAPSHOT.jar\META-INF

The remove the version from these paths- I used this MF file:

Manifest-Version: 1.0
Bnd-LastModified: 1417203916467
Build-Jdk: 1.7.0_67
Built-By: scottm
Bundle-Description: Maven Multimodule project for slingmodel.
Bundle-ManifestVersion: 2
Bundle-Name: slingmodel Bundle
Bundle-SymbolicName: com.adobe.community.slingmodel.slingmodel-bundle
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: com.adobe.community.slingmodel;uses:="com.google.common.
 cache,com.day.cq.wcm.api,org.apache.sling.models.annotations,org.apache
 .sling.api,javax.inject,org.apache.sling.api.resource,org.osgi.framewor
 k,org.osgi.service.component,org.slf4j";version="1.0.0.SNAPSHOT"
Import-Package: com.day.cq.wcm.api;version="[1.0,2)",com.google.common.c
 ache;version="[15.0,16)",javax.inject,org.apache.slin
 g.api;version="[2.2,3)",org.apache.sling.api.resource;version="[2.1,3)"
 ,org.apache.sling.models.annotations,org.osgi.framewo
 rk;version="[1.5,2)",org.osgi.service.component;version="[1.1,2)",org.s
 lf4j;version="[1.5,2)"
Service-Component: OSGI-INF/serviceComponents.xml
Tool: Bnd-1.50.0

 

 

Notice that the version is gone from these packages. Now it imports the bundle and places it into an active state. Make sure that you deploy the depedencies in a separate OSGi bundle fragment. 

See this community article for more information:

http://thecarlhall.wordpress.com/2012/01/19/understanding-the-unresolved-constraint-missing-resource...

View solution in original post

9 Replies

Avatar

Level 10

Can you please describe the structure of your bundle in more detail - are these:

<dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>15.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.models.api</artifactId>
            <version>1.0.0</version>
        </dependency>

the only dependencies that it has?

Avatar

Level 4

Theres are all the dependecies I have:

<!--  AEM 6.0 dependencies (includes all AEM dependencies) --> <dependency> <groupId>com.adobe.aem</groupId> <artifactId>aem-api</artifactId> <version>6.0.0.1</version> <scope>provided</scope> </dependency> <!--  Non-Adobe AEM dependencies --> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> <version>4.2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.apache.felix.scr.annotations</artifactId> <version>1.6.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.jcr</groupId> <artifactId>jcr</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.6</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.compendium</artifactId> <version>5.0.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>15.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.models.api</artifactId> <version>1.0.0</version> <scope>provided</scope> </dependency>

Avatar

Level 10

I want to duplicate your steps - judging from your POM - you are attempting to create a bundle that uses the Google Java guava-libraries. However - I doubt pulling in this lib will cause issues. I will double check to make sure. 

The issue here seems to be more related to your bundle and its dependency on javax.inject

Avatar

Level 10

As I suspected - the issue not with importing the Google Guava lib into AEM. This works nicely:

[img]Result.png[/img]

As you can see - this is an AEM 6 Touch UI Page component displaying the return value from an AEM service that uses the Guava lib.

Without seeing exactly how you setup your bundle - its hard to determine the exact cause. But the fact you are using this Google lib is not an issue as I ruled that out. 

I used this dependency in my POM for my test Guava project. Its similar to yours.

<dependencies>
       <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.compendium</artifactId>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
        </dependency>
                 
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.scr.annotations</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
         
     <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.commons.scheduler</artifactId>
            <version>2.3.3-R1232965</version>
            <scope>provided</scope>
        </dependency>
         
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        
        
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>
        
    </dependencies>

Avatar

Level 10

The other part of your bundle use sling models judging from your POM: org.apache.sling.models.api.

Here is a good community artilce that talks about how to work with Sling Models:

Sling Models for Fun and Profit

Avatar

Level 4

Thanks Scott for taking some time to help me. I really appreciate it.

I have created a simple test project here on Github, if you want to have a look:

https://github.com/danchapmanme/bundle-test.git

You can deploy the bundle using: mvn clean install -PautoInstallBundle

You will notice it installs but never gets activated. An exception is thrown which is viewable in the error log.

Avatar

Level 10

I am forking this and will look into this today.

Avatar

Correct answer by
Level 10

You are right - this bundle - the way it is setup has a dependency issue:

 org.apache.sling.scripting.java [215.0])
org.osgi.framework.BundleException: Uses constraint violation. Unable to resolve bundle revision com.mycompany.cq.bundle-test-bundle [394.0] because it is exposed to package 'javax.inject' from bundle revisions org.apache.sling.models.api [344.0] and org.apache.sling.scripting.java [215.0] via two dependency chains.

Chain 1:
  com.mycompany.cq.bundle-test-bundle [394.0]
    import: (&(osgi.wiring.package=javax.inject)(version>=0.0.0)(!(version>=1.0.0)))
     |
    export: osgi.wiring.package=javax.inject
  org.apache.sling.models.api [344.0]

Chain 2:
  com.mycompany.cq.bundle-test-bundle [394.0]
    import: (&(osgi.wiring.package=com.google.common.cache)(version>=15.0.0)(!(version>=16.0.0)))
     |
    export: osgi.wiring.package=com.google.common.cache; uses:=javax.inject
  com.google.guava [78.0]
    import: (osgi.wiring.package=javax.inject)
     |
    export: osgi.wiring.package=javax.inject
  org.apache.sling.scripting.java [215.0]
    at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3986)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2043)
    at org.apache.felix.framework

 

The issue here is the bundle trying to import the wrong versions of javax.inject and sling API. TO fix this issue, open the MANIFEST.MF file in the OSGi bundle using a tool like WinRAR. The path is:

slingmodel-bundle-1.0-SNAPSHOT.jar\META-INF

The remove the version from these paths- I used this MF file:

Manifest-Version: 1.0
Bnd-LastModified: 1417203916467
Build-Jdk: 1.7.0_67
Built-By: scottm
Bundle-Description: Maven Multimodule project for slingmodel.
Bundle-ManifestVersion: 2
Bundle-Name: slingmodel Bundle
Bundle-SymbolicName: com.adobe.community.slingmodel.slingmodel-bundle
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: com.adobe.community.slingmodel;uses:="com.google.common.
 cache,com.day.cq.wcm.api,org.apache.sling.models.annotations,org.apache
 .sling.api,javax.inject,org.apache.sling.api.resource,org.osgi.framewor
 k,org.osgi.service.component,org.slf4j";version="1.0.0.SNAPSHOT"
Import-Package: com.day.cq.wcm.api;version="[1.0,2)",com.google.common.c
 ache;version="[15.0,16)",javax.inject,org.apache.slin
 g.api;version="[2.2,3)",org.apache.sling.api.resource;version="[2.1,3)"
 ,org.apache.sling.models.annotations,org.osgi.framewo
 rk;version="[1.5,2)",org.osgi.service.component;version="[1.1,2)",org.s
 lf4j;version="[1.5,2)"
Service-Component: OSGI-INF/serviceComponents.xml
Tool: Bnd-1.50.0

 

 

Notice that the version is gone from these packages. Now it imports the bundle and places it into an active state. Make sure that you deploy the depedencies in a separate OSGi bundle fragment. 

See this community article for more information:

http://thecarlhall.wordpress.com/2012/01/19/understanding-the-unresolved-constraint-missing-resource...