Expand my Community achievements bar.

SOLVED

Including third part jar files in aemaacs

Avatar

Level 9

I have included third party jar file in my project, I got the following error 

[xxxxx ] in start level 20 but no bundle is exporting these for that start level

I found following article to fix this 

https://aemconcepts.com/aem-osgi/use-3rd-party-api-or-jar-or-dependency-in-aem/

adding 

-include-resource:cq-dam-processor-nui-1.1.840.jar -classpath:cq-dam-processor-nui-1.1.840.jar 
in core pom bnd-process section fixed above error. Bundle is active however all the services are in satisfied state
 
Screen Shot 2024-09-09 at 12.33.25 AM.png
Clicking on component shows me this
Reference osgi.ds.satisfying.conditionSatisfied
Service Name: org.osgi.service.condition.Condition
Target Filter: (osgi.condition.id=true)
Cardinality: 1..1
Policy: dynamic
Policy Option: reluctant
Screen Shot 2024-09-09 at 12.41.24 AM.png
 
There are multiple errors in error.log,  it seems bundle is not able to find the service classes  
 09.09.2024 01:12:37.892 *WARN* [FelixLogListener] org.apache.sling.engine.impl.filter.ServletFilterManager bundle org.apache.sling.engine:2.15.16 (567)[org.apache.sling.engine.impl.filter.ServletFilterManager(3528)] : Could not get service from ref [javax.servlet.Filter]
09.09.2024 01:12:37.967 *ERROR* [FelixLogListener] Events.Framework.org.apache.sling.engine FrameworkEvent ERROR (org.apache.felix.log.LogException: org.osgi.framework.ServiceException: Service factory exception: javax/servlet/Filter)
org.apache.felix.log.LogException: org.osgi.framework.ServiceException: Service factory exception: javax/servlet/Filter
org.apache.felix.log.LogException: java.lang.NoClassDefFoundError: org/apache/sling/api/resource/ResourceResolver
Attaching logs as well
If anyone come across this issue pls provide suggestions on how to resolve?
1 Accepted Solution

Avatar

Correct answer by
Level 6

Hi @Mshaji ,

The secret sauce is, 

 

Add 

-conditionalpackage: org.apache.sling.servlethelpers.*,com.demo.package.*

inside the bnd-process plugin goal. So your bnd-process of parent pom.xml should look like this:

 

<plugin>
                    <groupId>biz.aQute.bnd</groupId>
                    <artifactId>bnd-maven-plugin</artifactId>
                    <version>${bnd.version}</version>
                    <executions>
                        <execution>
                            <id>bnd-process</id>
                            <goals>
                                <goal>bnd-process</goal>
                            </goals>
                            <configuration>
                                <bnd>
                                    <![CDATA[
Bundle-Category: ${componentGroupName}
-exportcontents: ${removeall;${packages;VERSIONED};${packages;CONDITIONAL}}
-noextraheaders: true
-snapshot: SNAPSHOT
-conditionalpackage: org.apache.sling.resource.filter.*
Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
-plugin org.apache.sling.bnd.models.ModelsScannerPlugin
                                ]]>
                                </bnd>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

An excellant article explaining difference between conditionalpackage and includeresource is here - https://myaemlearnings.blogspot.com/2021/12/embed-third-party-dependency-using-bnd.html

 

Just adding the -conditionalpackage to your plugin should solve your issue. 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 6

Hi @Mshaji ,

The secret sauce is, 

 

Add 

-conditionalpackage: org.apache.sling.servlethelpers.*,com.demo.package.*

inside the bnd-process plugin goal. So your bnd-process of parent pom.xml should look like this:

 

<plugin>
                    <groupId>biz.aQute.bnd</groupId>
                    <artifactId>bnd-maven-plugin</artifactId>
                    <version>${bnd.version}</version>
                    <executions>
                        <execution>
                            <id>bnd-process</id>
                            <goals>
                                <goal>bnd-process</goal>
                            </goals>
                            <configuration>
                                <bnd>
                                    <![CDATA[
Bundle-Category: ${componentGroupName}
-exportcontents: ${removeall;${packages;VERSIONED};${packages;CONDITIONAL}}
-noextraheaders: true
-snapshot: SNAPSHOT
-conditionalpackage: org.apache.sling.resource.filter.*
Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
-plugin org.apache.sling.bnd.models.ModelsScannerPlugin
                                ]]>
                                </bnd>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

An excellant article explaining difference between conditionalpackage and includeresource is here - https://myaemlearnings.blogspot.com/2021/12/embed-third-party-dependency-using-bnd.html

 

Just adding the -conditionalpackage to your plugin should solve your issue.