问题描述:

This question is similar to one which are posted, but this is little different.

I have used Google guava and when maven install it gives the following error

Error executing command: Could not start bundle mvn:com.mycompany.webservices/dto/1.0.0 in feature(s) WebServicesGateway-0.0.0: Unresolved constraint in bundle

com.mycompany.webservices.dto [224]: Unable to resolve 224.0: missing requirement [224.0] osgi.wiring.package; (&(osgi.wiring.package=com.google.common.base)(version>=13.0.0)(!(version>=14.0.0

)))

when am marking the following in the pom.xml the maven install works fine.

<Import-Package>!com.google.common.base,

but this causes classDEFNotFound Exception during runtime.

java.lang.NoClassDefFoundError: com/google/common/base/Objects

I have tried with putting the version in the import to restrict the version number

<Import-Package>com.google.common.base;version="[13.0,13.0]",

I have tried to restrict it to 12.0, 11.0 and 10.0 but the error stays same.

I checked the maven .m2 repository and the jar file looks good.

Any suggestions ?

网友答案:

You have to put the guava libraries to your osgi environment, which would export the packages your bundle needs. The current version (13) of the guava-jar comes osgi ready. Just drop that jar into karaf's deploy folder and you should be fine.

About your solution trials: You should not need to manually set the Import-Package property in your pom in most cases - the maven bundle plugin does resolve that for you. If an Import-Package like com.google.guava appears in your bundle's manifest, that means you really use that package in your bundle - so manually excluding it will not solve the problem. Actually OSGi tries to protect you from the ClassNotFoundException by requiring the imports to be resolved before it starts the bundle, you have exploited that protection mechanism by setting the import-package property.

相关阅读:
Top