Topic
3 replies Latest Post - ‏2014-01-13T16:00:44Z by C7YC_David_Westerman
C7YC_David_Westerman
12 Posts
ACCEPTED ANSWER

Pinned topic Liberty Profile, OSGi, and Dependencies

‏2014-01-11T15:54:09Z |

I am trying to get a handle on using OSGi with Liberty Profile (8.5.5.Next), and am running into problems. It may just be that I'm not understanding some key part of the puzzle, but I don't know for sure what is missing.

 

I have an OSGi Application Project that contains a number of OSGi Bundle Projects. I am using Apache Commons Lang, so I made it a separate bundle 'apache.commons.lang' (this may not be the best way to handle this, but I was curious how you would use bundles in order to allow different versions of Commons Lang to be used by different apps). Here is my MANIFEST.MF for the bundle:

 

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: apache.commons.lang
Bundle-SymbolicName: apache.commons.lang
Bundle-Version: 3.1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.apache.commons.lang3,
org.apache.commons.lang3.builder,
org.apache.commons.lang3.concurrent,
...
org.apache.commons.lang3.tuple

 

 

This bundle is part of the OSGi Application, in its APPLICATION.MF:

 

Application-Name: DvdList.App
Application-SymbolicName: DvdList.App
Application-ManifestVersion: 1.0
Application-Version: 1.0.0.0
Application-Content: DvdList.API;version=1.0.0,
DvdList.Client;version=1.0.0,
DvdList.Common;version=1.0.0,
DvdList.JPA;version=1.0.0,
DvdList.Service;version=1.0.0,
DvdList.Config;version=1.0.0,
DvdList.Web;version=1.0.0,
apache.commons.collections;version=4.0.0,
apache.commons.lang;version=3.1.0
Manifest-Version: 1.0

 

 

During compile time, there are no errors, because the dynamic Plug-in Dependencies are being updated correctly to look for the jar in the right place.

 

However, when I run my application, I am getting runtime errors trying to find the class 'org.apache.commons.lang3.builder.ToStringBuilder':

Caused by: java.lang.ClassNotFoundException:
org.apache.commons.lang3.builder.ToStringBuilder cannot be found by osgi.identity; osgi.identity="DvdList.JPA";
type="osgi.bundle"; version:Version="1.0.0.0"

 

 

However, here is the MANIFEST.MF for the DvdList.JPA bundle which is trying to use the class:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: DvdList.JPA
Bundle-SymbolicName: DvdList.JPA
Bundle-Version: 1.0.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Meta-Persistence:
Import-Package: javax.naming,
javax.persistence;version="1.1.0",
javax.sql;version="0.0.0",
javax.transaction;version="1.1.0",
org.apache.commons.lang3.builder,
westerlywinds.dvdlist.common
Export-Package: westerlywinds.dvdlist.jpa
Bundle-Blueprint: OSGI-INF/blueprint/*.xml

 

To me, everything seems like it is correct. If I remove the Import-Package entry for 'org.apache.commons.lang3.builder' above, then I get compiler errors in the DvdList.JPA project. To me, this tells me that I've got the right entry in the MANIFEST.MF.

 

So the question is, what else do I need in order for the DvdList.JPA project to be able to find the 'org.apache.commons.lang3.builder.ToStringBuilder' class?

 

  • RichEllis
    RichEllis
    4 Posts
    ACCEPTED ANSWER

    Re: Liberty Profile, OSGi, and Dependencies

    ‏2014-01-13T11:18:52Z  in response to C7YC_David_Westerman

    It looks like the package wiring is ok, so it seems like the ToStringBuilder class is missing from the exported package at runtime. Does the built apache.commons.lang bundle definitely contain the class?

    • C7YC_David_Westerman
      12 Posts
      ACCEPTED ANSWER

      Re: Liberty Profile, OSGi, and Dependencies

      ‏2014-01-13T14:45:47Z  in response to RichEllis

      Thanks, Rich.

      The class is definitely in the jar. And if I remove the Import-Package for the package in the bundle that is getting the runtime error, I then get a compile error. So this leads me to believe that I've got the correct jar and class.

      I think I will try deploying this application on a regular WAS server, just to rule this out as being a Liberty Profile issue.

  • C7YC_David_Westerman
    12 Posts
    ACCEPTED ANSWER

    Re: Liberty Profile, OSGi, and Dependencies

    ‏2014-01-13T16:00:44Z  in response to C7YC_David_Westerman

    Okay, I found my problem. When I exported the project to an EBA, the Commons jar files were not actually being put into it. I needed to go into the Deployment Assembly section of the Properties, and add the jar file there.