OSGI - handling 3rd party JARs required by a bundle

前端 未结 6 1792
感情败类
感情败类 2020-12-02 12:07

I\'m just getting started with OSGI development and am struggling to understand how best to handle dependant JARs.

i.e. if I\'m creating a bundle the likelyhood is t

相关标签:
6条回答
  • 2020-12-02 12:44

    I would almost always bundle each jar separately. OSGi itself is meant for modularization and you take the whole system ad absurdum by not doing this.

    If you want to convert JARs into bundles you might want to use the BND Tool written by Peter Kriens. But first I would suggest you look for the bundle in the SpringSource Enterprise Bundle Repository if they haven't already done the work for you.

    0 讨论(0)
  • 2020-12-02 12:59

    Here is an example if you are using the Maven Bundle Plugin.

    Note: This plugin automatically imports packages that your dependencies need. This may or may not be a problem for you. Thankfully, you can suppress the packages you don't really need to import (see below).

        <Import-Package>
            <!-- this was imported by one of the dependencies; I don't really need it -->
            !org.apache.jackrabbit.test,
            *
        </Import-Package>
        <Include-Resource>
            lib/concurrent-1.3.4.jar,
            lib/jackrabbit-core-2.6.5.jar,
            lib/jackrabbit-spi-2.6.5.jar,
            lib/jackrabbit-spi-commons-2.6.5.jar,
            lib/lucene-core-3.6.0.jar,
            lib/tika-core-1.3.jar
        </Include-Resource>
        <Bundle-ClassPath>
            .,
            concurrent-1.3.4.jar,
            jackrabbit-core-2.6.5.jar,
            jackrabbit-spi-2.6.5.jar,
            jackrabbit-spi-commons-2.6.5.jar,
            lucene-core-3.6.0.jar,
            tika-core-1.3.jar
        </Bundle-ClassPath>
    
    0 讨论(0)
  • 2020-12-02 13:04

    You can include a third party jar inside your bundle by adding the third party jar to the root directory of the bundle jar file and then adding a bundle classpath header to the bundle's manifest, e.g.:

    Bundle-ClassPath: .,my3rdparty.jar
    

    If you want to place third party jar to subdirectory, specify the path without using heading ./, e.g

    Bundle-ClassPath: .,lib/my3rdparty.jar # (not ./lib/my3rdparty.jar)
    
    0 讨论(0)
  • 2020-12-02 13:06

    Can we use OSGI to override the bootstrap classloader jars loaded during runtime, like if we wanted to override JAXP1.4.5 available with Java7 to JAXP1.6, there is -Dendorese feature to override the default API to upgraded API. Can we able to do this thing with the help of OSGI.

    0 讨论(0)
  • 2020-12-02 13:07

    It is possible to embed non-OSGi dependencies into the bundle.

    An easy way to do this is to use Maven to manage your dependencies and Maven Bundle Plugin to build your bundle. Take a look at the <Embed-Dependency> and <Embed-Transitive> instructions of the Maven Bundle Plugin described in the section Embedding dependencies of the plug-in documentation page.

    As Roland pointed out this is not an ideal solution with respect to the intentions of OSGi, i.e. modularization and reuse of individual modules. However it might be pragmatic solution for time being until the 3rd-party dependencies can be converted into OSGi bundles.

    0 讨论(0)
  • 2020-12-02 13:08

    This thread is a bit old, but I wanted to point out one of the limitations of embedding dependencies. Recall that dependencies are at the jar level, but when you export packages some may need to come from the embedded dependencies. If this happens, you will end up with duplicate classes, one set inline in the top level bundle and another in the embedded jar. Of course, you can inline the entire embedded jar, but before you know it this propagates across your entire dependency chain. This is just one of the problems that Roland and others refer to.

    0 讨论(0)
提交回复
热议问题