Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Maven dependency when using opencsv : Unable to start bundle

Avatar

Level 3

I am trying to use opencsv in my AEM project. For that I have added the maven dependency as below in my core bundle pom.xml.

 

<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.1</version>
</dependency>

 

But after adding this dependency, my project bundle is showing installed status and I can see the below when anlaying the bundle.

org.apache.log -- Cannot be resolved

org.apache.avalon.framework.logger -- Cannot be resolved

 

Error.log :
missing requirement - Unresolved requirements: osgi.wiring.package; (osgi.wiring.package=org.apache.log)

 

Can someone help me understand if we need to add any more maven dependency when using opencsv in AEM?

 

 

Answer:

Thanks @ArpitVarshney for helping me fix this issue and Thank you @Albin_Issac for the valuable comments.
Adding the below dependencies in import-packages helped me resolve my issue. My bundles are up and running now.

<
plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
!org.apache.log,
!org.apache.avalon.framework.logger
</Import-Package>

<Embed-Dependency>*;
|opencsv
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @pn_2007 

Please add the maven dependency for the com.opencsv in your pom files.

<dependency>
     <groupId>com.opencsv</groupId>
     <artifactId>opencsv</artifactId>
     <version>4.1</version>
</dependency>

 

After that, verify the <Embed-Dependency> tag of maven-bundle-plugin [You can either include all the dependencies or you can configure to not include specific ones]. The scope attribute lets you configure which dependency jars you want to include based on their include scope. You should not include the dependencies which are only needed for compile and for the test.

Below is the example to add the com.opencsv to the embed dependency.

 

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>*;
|opencsv
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>

Regards,

Arpit Varshney 

View solution in original post

10 Replies

Avatar

Community Advisor

are you embedding opencsv dependency to the bundle? only adding the dependency to the pom.xml will not include the dependency to the bundle or server.

is there any issue related to com.opencsv packages in the bundle? Can you try embedding the opencsv bundle to the custom bundle package, please follow the below steps

For bnd-maven-plugin(if you are using latest bnd-maven-plugin)

Add new plug in to the core module

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependency</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>opencsv</includeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>

Modify the bnd-maven-plugin configurations as below(sample configuration, add your configurations)

<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[
Bundle-Category: demos
Import-Package: javax.annotation;version=0.0.0,com.opencsv,*
-exportcontents: ${packages;VERSIONED},\
com.opencsv.*

Include-Resource: target/dependency/opencsv-4.1.jar
Bundle-ClassPath: ., opencsv-4.1.jar
Sling-Model-Packages: demos.core.models
-snapshot: ${tstamp;yyyyMMddHHmmssSSS}
Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin


]]></bnd>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.caconfig.bnd-plugin</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
</plugin>

For maven-bundle-plugin(if you are using maven-bundle-plugin)

Add the below configurations to maven-bundle-plugin 

<Embed-Transitive>true</Embed-Transitive>

<Embed-Dependency>opencsv;scope=compile|runtime;inline=true</Embed-Dependency>

Avatar

Level 3

Hi @Albin_Issac

 

My core bundle pom.xml already have an entry like this.

 

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<!-- Do not inline jars, include as jar files -->
<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Sling-Model-Packages>

</Sling-Model-Packages>
<!-- There is a problem with javax.inject which is exported by multiple
packages, including from Guava. Because Guava is a dependency already there
is no need to create the import declaration which just confuses Felix. -->
<Import-Package>
!com.jcraft.jzlib,!android.util,!org.bouncycastle.jce,!org.bouncycastle.jce.spec,
javax.inject;version="[1.0,2)",
com.adobe.cq.commerce.api;version="[4.0.0,5)",com.adobe.cq.commerce.common;version="[3.0,4)",
*
</Import-Package>
</instructions>
</configuration>
</plugin>

 

I tried changing the inine to true and build again. That too did not fix the issue

Avatar

Correct answer by
Community Advisor

Hi @pn_2007 

Please add the maven dependency for the com.opencsv in your pom files.

<dependency>
     <groupId>com.opencsv</groupId>
     <artifactId>opencsv</artifactId>
     <version>4.1</version>
</dependency>

 

After that, verify the <Embed-Dependency> tag of maven-bundle-plugin [You can either include all the dependencies or you can configure to not include specific ones]. The scope attribute lets you configure which dependency jars you want to include based on their include scope. You should not include the dependencies which are only needed for compile and for the test.

Below is the example to add the com.opencsv to the embed dependency.

 

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>*;
|opencsv
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>

Regards,

Arpit Varshney 

Avatar

Level 3

Hi @ArpitVarshney, My core bundle pom.xml has already included * as dependency as below. 

 

 

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<!-- Do not inline jars, include as jar files -->
<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Sling-Model-Packages>

</Sling-Model-Packages>
<!-- There is a problem with javax.inject which is exported by multiple
packages, including from Guava. Because Guava is a dependency already there
is no need to create the import declaration which just confuses Felix. -->
<Import-Package>
!com.jcraft.jzlib,!android.util,!org.bouncycastle.jce,!org.bouncycastle.jce.spec,
javax.inject;version="[1.0,2)",
com.adobe.cq.commerce.api;version="[4.0.0,5)",com.adobe.cq.commerce.common;version="[3.0,4)",
*
</Import-Package>
</instructions>
</configuration>
</plugin>

 

I tried changing the inine to true and build again. That too did not fix the issue

Avatar

Community Advisor

Hi @pn_2007 

 

Please add !org.apache.log & !org.apache.avalon.framework.logger in existing <Import-Package> tag of maven-bundle-plugin like below.

 

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
!org.apache.log,
!org.apache.avalon.framework.logger
</Import-Package>

<Embed-Dependency>*;
|opencsv
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>

 

Avatar

Level 3
Thank @ArpitVarshney. That fixed the issue. Thanks a lot. You saved my day

Avatar

Community Advisor

No problem @pn_2007 , you can mark my answer as correct if that fixes your issue so that it will be good for other