Monday 20 February 2017

javax.inject,version=[0.0,1) -- Cannot be resolved

Sling Models is a way to create model objects which are automatically mapped from Sling objects, typically resources but also request objects.
This article explains how to use sling models in AEM. But, If you want to use Sling models with AEM 6.2, you might encounter some dependency issues.
Recently I faced a problem when my AEM project stopped working. The project was created using Maven archetype 10. It was working fine until I was on AEM 6.1. When I tried deploying it to AEM 6.2, the bundle was not coming to Active state. Later while debugging, I found out that it was not able to find a particular dependency. I was seeing something like below in the console.
javax.inject,version=[0.0,1) -- Cannot be resolved
Solved by adding this line in yourproject.core pom file
(with in the maven-bundle-plugin)
<Import-Package>javax.inject;version=0.0.0,*</Import-Package>

Here is the plugin after adding that line


<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
    <instructions>
    <!-- Import any version of javax.inject, to allow running on multiple versions of AEM -->
    <Import-Package>javax.inject;version=0.0.0,*</Import-Package>
       <Sling-Model-Packages>
             com.yourproject.core
        </Sling-Model-Packages>
      <Export-Package>com.yourproject.core.*</Export-Package>
     </instructions>
     </configuration>
</plugin>

No comments :

Post a Comment