How to handle Import-Package entries which come from jars on the Bundle-Classpath?

前端 未结 2 830
囚心锁ツ
囚心锁ツ 2020-12-21 07:19

I have put a few jars on my Bundle-Classpath. The line below shows the entry in my pom.xml, which uses the Felix plugin to create the manigest.mf for the bundle.

<         


        
2条回答
  •  时光说笑
    2020-12-21 08:08

    When you embed any jar via Embed-Dependency tag then the maven-bundle-plugin would analyze that jar also and add the referred packages to the host bundle Import-Package list. Mostly such packages are optional depending on the feature used. For example in your usecase the H2 jar has dependency on Lucene, Servlet API for certain features. if your usage scenario does not require these features then you can mark these packages as optional

    
            org.apache.felix
            maven-bundle-plugin
            2.3.5
            true
            
              NONE
              
                ${project.artifactId}
                ..
                
                  h2
                
                
                  org.osgi.service.jdbc.*;
                  org.apache.lucene.*;
                  javax.transaction.*;resolution:=optional,
                  *
                
              
            
          
    

    In above config we mark such packages as optional. The main problem is to determine the package list depending on your usage

    One quick and dirty way is to mark all as optional imports. Should be used as a last resort. As some valid imports would be marked optional and OSGi fwk would not be able to check them.

            
              *;resolution:=optional
            
    

    Also note that H2 jar is a valid OSGi bundle so you can deploy it directly.

提交回复
热议问题