com.google.gson,version=[2.2,3) -- Cannot be resolved in bundle - Adobe Experience Manager(AEM)
I was able compile and deploy the bundle successfully with gson dependency but the bundle is not getting started with the error "com.google.gson,version=[2.2,3) -- Cannot be resolved in bundle" in Adobe Experience Manager(AEM)The root cause of the problem is the gson jar is not available in the server for bundle access.
This issue can be resolved by following any of the below approach.
1. Export the gson package - com.google.gson.*
<dependency><groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Activator>com.sample.activator.Activator</Bundle-Activator>
<Import-Package>*,com.sample.*</Import-Package>
<Export-Package>com.sample.*,com.google.gson.*</Export-Package>
<Bundle-SymbolicName>com.sample</Bundle-SymbolicName>
<Bundle-Vendor>Sample</Bundle-Vendor>
<Bundle-Category>Sample</Bundle-Category>
<Embed-Directory>dependencies</Embed-Directory>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
2. Add the gson jar in the bundle class path
Specify the gson dependency scpes as compile or runtime(compile is the default scope)<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency
The gson jar will be included in the bundle classpath.
The dependencies with what are all the scopes are included in the bundle classpath is configured in maven-bundle-plugin
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<configuration>
<instructions>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Directory>OSGI-INF/lib</Embed-Directory>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
3. Install the gson jar as bundle from felix console
The above two approaches the gson jar will be only available for the bundle but in this approach the jar will be available for all the bundles.Go to http://localhost:4502/system/console/bundles
Click on Install/Update
Select Start Bundle and choose the gson jar.
Click on Install or Update.
Thanks Albin for the solution.It was really helpful.
ReplyDeleteThanks, it's really helpful. I keep experiencing this issue for a few packages. This solution definitely helps to get all my issues resolved.
ReplyDeleteHow could I find the correct version of dependency instead of including them in my bundle?
Thanks!
ReplyDeleteFYI: Closing ">" is missing here: </dependency
Thanks, corrected now
Delete