문제

I am using in my osgi application the querydsl library. The artifact querydsl-jpa has hibernate-jpa-2.0-api as a dependency.

I have added such a exclusion in my pom.xml since I dont use hibernate. Still when I try to start my service (through a karaf features.xml file), I get this:

Error executing command: Could not start bundle mvn:com.mysema.querydsl/querydsl-jpa/2.5.0 in feature(s) querydsl-jpa-2.5.0: Unresolved constraint in bundle com.mysema.querydsl.jpa [223]: Unable to resolve 223.0: missing requirement [223.0] package; (&(package=org.hibernate)(version>=3.6.8.Final))

mvn project dependency:tree does not return any hibernate dependency. Does this means that the osgi dependency is determined exclusively by the manifest file of the querydsl bundle even if the dependency is explicitly excluded?

    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
        <version>2.5.0</version>
        <exclusions>
        <exclusion>
        <groupId>org.hibernate.javax.persistence</groupId>
  <artifactId>hibernate-jpa-2.0-api</artifactId>
        </exclusion>
        </exclusions>
    </dependency>

and a extract from the features.xml

 <feature name='querydsl-jpa' version='2.5.0'>
  <bundle>mvn:org.apache.felix/org.osgi.compendium/1.4.0</bundle>
  <bundle>mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1</bundle>
  <bundle>mvn:com.mysema.querydsl/querydsl-core/2.5.0</bundle>
  <bundle>mvn:com.mysema.commons/mysema-commons-lang/0.2.2</bundle>
  <bundle>mvn:com.mysema.querydsl/querydsl-sql/2.5.0</bundle>
  <bundle>mvn:com.mysema.querydsl/querydsl-jpa/2.5.0</bundle>
</feature>
도움이 되었습니까?

해결책

The pom.xml determines what happens at build time, not at runtime. It's easy to muddle dependencies declared in a pom and dependencies declared in a manifest, since both seem to involve dependencies, but they're actually very different. The OSGi runtime doesn't know or care about maven, so it never looks at your pom files. The way OSGi communicates about dependencies is through the manifest. Obviously, what's in the pom can influence what's in the manifest, but only for bundles you build. Here, you're not rebuilding the querydsl bundle, so the manifest is the one it was shipped with.

If that bundle declares a dependency on hibernate, you should assume it really does need hibernate. If you're sure the dependency is optional, you should report a bug to the owners of the bundle. While you're waiting for a fix, your options are then to rebuild the bundle, adding an optional=true directive to the hibernate bundle, or make a dummy bundle which exports the missing hibernate packages. This will get the querydsl bundle starting, but I'd be very cautious with this approach. You're using hacks to bypass OSGi's safety mechanisms, and you run the risk of getting NoClassDef exceptions and other failures at runtime, unless the codepaths which use hibernate are totally unused.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top