Monday, July 18, 2011

Karaf Exceptions: "Missing Constraint: Import Package"

One of the toughest things about working with Karaf, is that the error messages created by Karaf are not clear to folks new to OSGi. My "Karaf Exceptions" set of blogs are here to provide help in navigating these tough waters. Our first exception is "Missing Constraint: Import Package".

(Blatantly plagiarized and improved from my original post on the Karaf User Mailing List)

Lets set up the scenario. A user asked the dev's this:

I'm unable to activate a bundle and am getting - "could not be resolved. Reason: Missing Constraint: Import-Package: org.springframework.web.util; version="3.0.0"".

What configuration setting am I missing?

This error usually arises when the bundle in question is attempting to wire to a package that is not present in the OSGi environment. To verify this, do the following:
1) ensure that the packages isn't already available within Karaf

root@karaf> exports | grep org.springframework.web.util

2) If that command doesn't return anything, then you should find the bundle that contains the package you need, and install that into your container. Doing a simple search for that package on a sonatype repository should let you see the proper bundle.

Ok, this will work for most cases. But there are corner cases where you'll get this error if a third-party bundle can't access a given package. For example, if you're using Hibernate and C3P0 to access a MySQL database. You'll get the above error when C3P0 attempts to get access to mysql driver. Unfortunately, the C3P0 bundle doesn't wire to the driver, so you need to create a "fragment" that adds an import statement to the C3P0 bundle. This is in itself a sticky issue deserving its own blog, so I'll handle it there.

Please try this and let me know if it helps.

No comments:

Post a Comment