7

I'm having trouble with the MANIFEST.MF generated by the maven-bundle-plugin. For some reason, when I have the version numbers listed in the <Import-Package> field, the OSGi framework doesn't load my bundle.

I've experimented and noticed that if I remove the version numbers in the manifest, then the bundle is properly loaded.

How can I instruct maven-bundle-plugin to skip the version numbers?

Currently, it generates:

Import-Package: com.ghc.ghTester.expressions,org.apache.ws.security.proc
 essor;version="[1.5,2)",org.apache.ws.security;version="[1.5,2)",org.ap
 ache.ws.security.message;version="[1.5,2)",org.apache.ws.security.compo
 nents.crypto;version="[1.5,2)",org.apache.ws.security.message.token;ver
 sion="[1.5,2)"

But I need it to generate:

Import-Package: com.ghc.ghTester.expressions,org.apache.ws.security.proc essor,org.apache.ws.security,org.apache.ws.security.message,org.apache. ws.security.components.crypto,org.apache.ws.security.message.token

My plugin config is:

        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>3.0.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId};singleton:=true</Bundle-SymbolicName>
                    <Bundle-Name>${pom.name}</Bundle-Name>
                    <Bundle-Version>${pom.version}</Bundle-Version>
                    <Bundle-ClassPath>{maven-dependencies},.</Bundle-ClassPath>
                    <Embed-Dependency>*;scope=compile</Embed-Dependency>
                    <Export-Package/> <!-- nothing for this bundle to export -->
                    <Import-Package>com.ghc.ghTester.expressions,org.apache.ws.*</Import-Package>
                </instructions>
            </configuration>
        </plugin>

If I try loading it with the version, I get the following error:

org.osgi.framework.BundleException: Could not resolve module: com.rit.message-level-security [978]
  Unresolved requirement: Import-Package: org.apache.ws.security; version="[1.0.0,3.0.0)"

        at org.eclipse.osgi.container.Module.start(Module.java:434)
        at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:393)
        at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:412)
        at com.ghc.ghTester.Activator.installTempBundle(Activator.java:157)
Eric B.
  • 23,425
  • 50
  • 169
  • 316
  • It's not a good practice to omit the version. what is the error you have when you deploy your bundle ? you can't use the version deployed by your dependencies ? – Jérémie B Mar 23 '16 at 21:42
  • 1
    I realize that it isn't a good practice, but this is a very limited plugin that will be used in a very limited framework. The framework is completely out of my control, and I don't even see error messages when I try to load my bundle. From trial and error, I noticed that it was the version numbers that were causing issues, and the easiest way to circumvent that was to drop the versions. – Eric B. Mar 23 '16 at 21:44
  • If you are using felix, you can maybe use the `exports` command on the gogo shell to find the version of the package exported ? I don't think it's possible to omit the version with this plugin.. maybe something like `version=[0,9)` can work, but it's really ugly and defeat the purpose of the dependencies management of osgi – Jérémie B Mar 23 '16 at 21:50
  • I finally managed to get some logging out, and have pasted the error above. Basically, cannot find the version. – Eric B. Mar 23 '16 at 21:52
  • check is wss4j is deployed, and the version of this bundle – Jérémie B Mar 23 '16 at 21:56
  • I tried putting the version in my pom, but no idea how to write it. I've tried org.apache.ws.*;version=[0,9), but it interprets the , in the version number as a separator for the next package. Any ideas? I've tried escaping with a \ but that doesn't help. – Eric B. Mar 23 '16 at 22:00
  • The documentation is here : http://www.aqute.biz/Bnd/Format in "Import-Package". use a double quote – Jérémie B Mar 23 '16 at 22:06
  • 2
    You can define: packageName;version="0". That means all versions are accepted as if no range is specified, it means greather or equal to the specified version. And use the double code as it was mentioned in one of the previous comments. – Balazs Zsoldos Mar 23 '16 at 22:33
  • @JérémieB Is there anyway to query the framework and see which bundles are actually loaded? – Eric B. Mar 24 '16 at 02:14

3 Answers3

8

Adding version=! in Import-Package section to each of the bundles you want to omit version from would do the trick.

<Import-Package>
    com.ghc.ghTester.expressions;version=!,
    org.apache.ws.security.processor;version=!,
    org.apache.ws.security;version=!,
    org.apache.ws.security.message;version=!,
    org.apache.ws.security.components.crypto;version=!,
    org.apache.ws.security.message.token;version=!,
    *
</Import-Package>
Dmitry
  • 419
  • 3
  • 9
2

You can disable Import-Package versions using the following configuration:

<_consumer-policy>$${range;[--,++)}</_consumer-policy>
cleberz
  • 601
  • 7
  • 11
Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
1

You could start writing your imports manually like you did with "com.ghc.ghTester.expressions"

<Import-Package> 
com.ghc.ghTester.expressions,
org.apache.ws.security.processor,
org.apache.ws.security,
org.apache.ws.security.message,
org.apache.ws.security.components.crypto,
org.apache.ws.security.message.token
</Import-Package>

Even though this is not good practice as mentioned in the comments it should do the trick. But if you need additional imports later on you have to add them manually too.

By the way. The values for

<Bundle-Name>${pom.name}</Bundle-Name>
<Bundle-Version>${pom.version}</Bundle-Version>

do default to the values you are providing. See http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html Section: Default Behaviour

Naxos84
  • 1,890
  • 1
  • 22
  • 34