简体   繁体   中英

maven-bundle-plugin embed dependency failed to deploy bundle into OSGi container

I have a maven project floodlight. It runs good with eclipse. Then I use bundle-plugin to generate bundle and embed all dependencies into single target bundle with <embed-dependenciy> . Here is the pom.xml:

<groupId>net.floodlightcontroller</groupId>
<artifactId>floodlight</artifactId>
<version>master</version>
<packaging>bundle</packaging>
<build>
  <plugins>
    <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
     <instructions>
        <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
        <Embed-Transitive>true</Embed-Transitive>
        <Bundle-Activator>net.floodlightcontroller.core.Activator</Bundle-Activator>
        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
    </instructions>
  </configuration>
  </plugin>
 </plugins>
<build>

I have checked the target structure. All the dependencies are included. Then I check the manifest.mf:

Import-Package:  
COM.jrockit.reflect,COM.newmonics.PercClassLoader,com.google.protobuf,com.informix.jdbc,
com.kenai.jnr.x86asm,groovy.lang,javax.annotation,javax.jms,javax.mail,
javax.mail.internet,javax.management,javax.naming,javax.net,javax.net.ssl,javax.script,
*
*
*

I am wondering why it still imports so many package since I have already embeded all the dependencies into the single bundle. When I deploy the bundle into OSGi container and start it, I got Error:

Unable to start bundle 402: Unresolved constraint in bundle floodlight [402]: 
Unable to resolve 402.0: missing requirement [402.0] osgi.wiring.package;   
(osgi.wiring.package=COM.jrockit.reflect)

COM.jrockit.reflect is the first package listed in the import-package. But it is not listed in the export-package. Is this package needed at runtime? Can anyone help me?

It is a sad practice that many jars have more dependencies in their code than they declare in their pom. They are often in parts of the code that 'bridge' environments. Ie when the jar is executed in for example jrockit or groovy, it can leverage it but the core code is not really needing this dependency. Additionally, the javax packages should likely be imported from your app server. These are usually in the 'provided' scope in maven.

In general, you can make these dependencies optional and pray there are no core code paths to it. You can make them optional in bnd with:

<_import-package>
   javax.*, 
   COM.jrockit.*;
     COM.newmonics.*; 
     com.google.protobuf;
     com.informix.jdbc;
     com.kenai.jnr.x86asm;
     groovy.lang; 
       resolution:=optional, 
   *
</_import-package>

Don't forget the '*' at the end, it provides the mask for the normal imports.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM