Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude version numbers from Import-Package with maven-bundle-plugin?

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)
like image 889
Eric B. Avatar asked Mar 23 '16 21:03

Eric B.


2 Answers

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>
like image 147
Dmitry Avatar answered Nov 17 '22 13:11

Dmitry


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

<_consumer-policy>$${range;[--,++)}</_consumer-policy>
like image 30
Andreas Veithen Avatar answered Nov 17 '22 12:11

Andreas Veithen