Can't run OSGi wrapper bundle in Eclipse; .jar is building okay, but how do I also copy files into target/classes?

StackOverflow https://stackoverflow.com/questions/16529388

Question

First of all, I know a number of questions have been asked before about wrapping existing Maven dependencies as OSGi bundles, but I have a problem which I don't see directly addressed in any of those answers...

The bundle jar for the problematic project is actually being built successfully, with all the dependencies and appropriate metadata generated and copied into it. The outstanding issue is that the target/classes directory remains empty aside from META-INF/MANIFEST.MF, which means launching the bundle in Equinox as part of an OSGi run configuration from within Eclipse doesn't work.

I know that the .jar itself in target is built properly, as after copying its contents into target/classes manually I can launch it and everything works as expected.

    <plugin>
      <groupId>org.apache.felix</groupId>
      <artifactId>maven-bundle-plugin</artifactId>
      <version>2.4.0-SNAPSHOT</version>
      <extensions>true</extensions>
      <configuration>
        <instructions>
          <Export-Package></Export-Package>
          <Private-Package>*</Private-Package>
          <Require-Capability>osgi.extender; filter:="osgi.extender=osgi.serviceloader.registrar)"</Require-Capability>
          <Provide-Capability>osgi.serviceloader; osgi.serviceloader=javax.script.ScriptEngineFactory</Provide-Capability>
          <Import-Package></Import-Package>
          <Embed-Transitive>true</Embed-Transitive>
          <Embed-Dependency>*;scope=runtime|compile;inline=true</Embed-Dependency>
          <Service-Component>*</Service-Component>
          <_dsannotations>*</_dsannotations>
        </instructions>
        <archive>
          <addMavenDescriptor>true</addMavenDescriptor>
        </archive>
      </configuration>
    </plugin>

The important lines being, I suppose:

          <Embed-Transitive>true</Embed-Transitive>
          <Embed-Dependency>*;scope=runtime|compile;inline=true</Embed-Dependency>

Does anyone know of another method of wrapping OSGi bundles in Maven projects such that everything is copied into target/classes as well as the bundle jar? Or of a way to ask the Eclipse run configuration to look for the .jar itself rather than looking in this directory?

The thought just occurred to me this might be solvable as a hacky post-build Maven step to extract the jar into target/classes, though this is obviously far from ideal. Perhaps I could use profiles to limit it to Eclipse use or something, though I've not had to deal with that before so I'm unsure...

Thanks in advance for any help!

Était-ce utile?

La solution

Seems the answer to this is very simple. All we need to do is add <unpackBundle>true</unpackBundle> under the configuration of maven-bundle-plugin. In fact it seems it's not even sensible to only perform this step in a specific 'eclipse' profile. See http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html#ApacheFelixMavenBundlePlugin%28BND%29-Unpackingbundlecontentsto%27target/classes%27 for an explanation of why this is the case.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top