Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to convert third party jar files into bundles?

Avatar

Level 4

Hi,

I have a java project. Which is using some 3rd party jar files. Dependencies for those jar files not available. I want to integrate that java project into AEM. How to convert those 3rd party jar files into bundles and how to import them in my AEM project?

1 Accepted Solution

Avatar

Correct answer by
Employee

If those jar files are not required by your other bundles, then why not simply embed them in your custom bundle[1]? There is no need to create more bundles for the sake of it, I have been on projects where this has happened and often, simply embedding the jars would have been sufficient.

Regards,

Opkar

[1] http://www.sergiolopes.eu/2014/04/adding-jars-to-osgi-bundles-with-maven/

View solution in original post

6 Replies

Avatar

Administrator

Hi 

There is a community article covering jar to OSGI bundle.

Link:- https://helpx.adobe.com/experience-manager/kb/ConvertAJarIntoOsgiBundle.html

Answer, Resolution

Here's a very simple way of turning an existing jar file in an OSGi bundle, while keeping control on exported packages.

The example creates an OSGi bundle from the attached junit-4.4.jar.

Note: The method below only works in a scenario where the jar file has no dependencies on other external jar files.

 

  1. Start by creating a the jar's manifest file:
    Manifest-Version: 1.0 Created-By: myself Bundle-ManifestVersion: 2 Bundle-Name: JUnit 4.4 bundle Bundle-Description: Package junit 4.4 in an OSGi bundle Bundle-Version: 4.4.0 Bundle-ClassPath: .,junit-4.4.jar Bundle-SymbolicName: org.junit.framework Export-Package: junit.framework,junit.extensions,org.junit.runner,org.junit,junit.textui
     
    • Bundle-ClassPath header is set to allow embedding the original jar as is. Make sure its value matches the filename of the jar that you are going to embed in the bundle.
    • Export-Package is a list of packages contained in the jar that you would like to make available to other bundles running in the OSGi Container.
  2. Jar file
    Get the jar file, in our case fromhttp://mirrors.ibiblio.org/pub/mirrors/maven2/junit/junit/4.4/junit-4.4.jar
  3. Create the bundle jar file by running the following command:
    jar cvfm junit-4.4-bundle.jar manifest.txt junit-4.4.jar

    Where manifest.txt is the name of the manifest file created above.

    That's it - the resulting jar file (attached to this page as an example) is an OSGi bundle the exports the packages listed in Export-Package above, using the classes of the embedded junit-4.4.jar.

I hope this would help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Level 4

kautuksahni wrote...

Hi 

There is a community article covering jar to OSGI bundle.

Link:- https://helpx.adobe.com/experience-manager/kb/ConvertAJarIntoOsgiBundle.html

Answer, Resolution

Here's a very simple way of turning an existing jar file in an OSGi bundle, while keeping control on exported packages.

The example creates an OSGi bundle from the attached junit-4.4.jar.

Note: The method below only works in a scenario where the jar file has no dependencies on other external jar files.

 

  1. Start by creating a the jar's manifest file:
    Manifest-Version: 1.0 Created-By: myself Bundle-ManifestVersion: 2 Bundle-Name: JUnit 4.4 bundle Bundle-Description: Package junit 4.4 in an OSGi bundle Bundle-Version: 4.4.0 Bundle-ClassPath: .,junit-4.4.jar Bundle-SymbolicName: org.junit.framework Export-Package: junit.framework,junit.extensions,org.junit.runner,org.junit,junit.textui
     
    • Bundle-ClassPath header is set to allow embedding the original jar as is. Make sure its value matches the filename of the jar that you are going to embed in the bundle.
    • Export-Package is a list of packages contained in the jar that you would like to make available to other bundles running in the OSGi Container.
  2. Jar file
    Get the jar file, in our case fromhttp://mirrors.ibiblio.org/pub/mirrors/maven2/junit/junit/4.4/junit-4.4.jar
  3. Create the bundle jar file by running the following command:
    jar cvfm junit-4.4-bundle.jar manifest.txt junit-4.4.jar

    Where manifest.txt is the name of the manifest file created above.

    That's it - the resulting jar file (attached to this page as an example) is an OSGi bundle the exports the packages listed in Export-Package above, using the classes of the embedded junit-4.4.jar.

I hope this would help you.

Thanks and Regards

Kautuk Sahni

 

Thanks Kautunk Sahni,

But, my jar file has dependency on other jar files. 

Avatar

Level 10

You can use an Eclipse plugin project. It works very nicely. We have a lot of community articles that show how to do this task. For example, notice how we wrap the simple JSON JAR in this article:

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

Avatar

Correct answer by
Employee

If those jar files are not required by your other bundles, then why not simply embed them in your custom bundle[1]? There is no need to create more bundles for the sake of it, I have been on projects where this has happened and often, simply embedding the jars would have been sufficient.

Regards,

Opkar

[1] http://www.sergiolopes.eu/2014/04/adding-jars-to-osgi-bundles-with-maven/

Avatar

Administrator

Hi 

You may also refer to this article Link:http://www.wemblog.com/2012/04/how-to-integrate-3rd-party-jar-file-in.html .

I hope this would help you.

And thank you Opkar Gill, this is new learning for me :).

Thanks and Regards

Kautuk Sahni



Kautuk Sahni