Expand my Community achievements bar.

SOLVED

Question Regarding Third Party Jar

Avatar

Former Community Member

Hi,

I have a question regarding "use of third party jar" in AEM 6.0 SP2. I am listing down steps which i performed, hoping to get some solution :

  • I wrote a standalone java program which uses three jar files internally which i wanted to move to AEM ( wanted to make same functionality as a workflow method)
  • I created OSGI bundle jar (for all three) using eclipse plugin and imported through felix console. Once imported i stopped getting class not found exception for third party jar class in my workflow class.
  • Although my workflow class started throwing exception for one of java specific class (since it internally uses that) : javax.swing.event.EventListenerList
  • Then i came to know that i might need to add my third party jar file as fragment bundle, for it to pick java 7 specific class files (manifest entry) :
  •             Fragment-Host: org.apache.felix.framework; extension:=framework
  • After making this jar as fragment bundle and several restart now i am getting class not found exception for original jar again.

 

I can see that jar/class is available through "depfinder" but its not getting picked up by my custom workflow class. Any suggestion to debug would be really helpful.

~TD

1 Accepted Solution

Avatar

Correct answer by
Level 10

See this community article that uses two OSGi bundles. One that defines a sling servlet - the main OSGi. The other uses a bundle fragment that wraps simple JSON JAR into an OSGi fragment. 

https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

Now in this example - we need to include simple JSON package in our POM file:

 <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>

Make sure that you are including dependencies in your POM file to lists the packages in the OSGi fragments. 

This is maybe where your issue came from. If you build a custom JAR and loaded them into AEM via OSGi fragment/felix - that is all good.

However - in your Maven POM file - you still need to include them as dependencies so your main OSGi bundle can use the classes.  However - the custom JAR files are not located in a public Maven repo -- like the simple JSON JAR is. 

In your case - you need to setup Maven to use a local repo. See:

http://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-in-maven-project

View solution in original post

3 Replies

Avatar

Level 10

The issue seems to be with the OSGi bundle that contains your custom workflow class.

Looks like your successfully deployed the OCGi fragments and that contain the custom classes. 

Does this OSGi bundle contain a Manifest file that includes packages defined in the custom JARs? 

For example:

Manifest-Version: 1.0
Bnd-LastModified: 1414596063210
Build-Jdk: 1.7.0_67
Built-By: scottm
Bundle-Description: Maven Multimodule project for restful-training.
Bundle-ManifestVersion: 2
Bundle-Name: restful-training Bundle
Bundle-SymbolicName: com.adobe.restservice.restful-bundle
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: com.adobe.restservice;uses:="org.apache.http.impl.client
 ,org.apache.http.conn,org.apache.http.client.methods,org.apache.http,or
 g.osgi.framework,org.osgi.service.component,org.slf4j";version="1.0.0.S
 NAPSHOT"
Import-Package: org.apache.http,org.apache.http.client.methods,org.apach
 e.http.conn,org.apache.http.impl.client,org.osgi.framework;version="[1.
 5,2)",org.osgi.service.component;version="[1.1,2)",org.slf4j;version="[
 1.5,2)"

Service-Component: OSGI-INF/serviceComponents.xml
Tool: Bnd-1.50.0

Avatar

Level 10

If you do not have the import section in the MF file (that pulls in the packages defined in the custom JARS and deployed as fragments)- then you will encounter errors. 

Avatar

Correct answer by
Level 10

See this community article that uses two OSGi bundles. One that defines a sling servlet - the main OSGi. The other uses a bundle fragment that wraps simple JSON JAR into an OSGi fragment. 

https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

Now in this example - we need to include simple JSON package in our POM file:

 <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>

Make sure that you are including dependencies in your POM file to lists the packages in the OSGi fragments. 

This is maybe where your issue came from. If you build a custom JAR and loaded them into AEM via OSGi fragment/felix - that is all good.

However - in your Maven POM file - you still need to include them as dependencies so your main OSGi bundle can use the classes.  However - the custom JAR files are not located in a public Maven repo -- like the simple JSON JAR is. 

In your case - you need to setup Maven to use a local repo. See:

http://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-in-maven-project