How to create OSGi bundle from jar library?

前端 未结 6 800
-上瘾入骨i
-上瘾入骨i 2020-12-01 08:27

How to create OSGi bundle from jar library?

6条回答
  •  一向
    一向 (楼主)
    2020-12-01 08:55

    Late arrival to the party:

    If you're using Gradle, you can add the jar as a normal dependency of your project if you apply the osgi-run plugin.

    The osgi-run plugin will wrap the jar transparently into a bundle for you, exporting every package in it and calculating all its imports. As Gradle will know the jar's transitive dependencies, it will do the same for them as well, if necessary.

    The jar(s) will be part of the OSGi runtime osgi-run creates, which you can then start up with gradle runOsgi or gradle createOsgi, then executing either the run.sh or run.bat scripts.

    The actual wrapping is done by Bnd, the swiss knife of the OSGi world, of course.

    If you want to configure how the wrapping happens (what should be imported/exported, usually), you can do it easily in the Gradle build file, see the documentation for details.

    Example:

    wrapInstructions {
        // use regex to match file name of dependency
        manifest( "c3p0.*" ) {
            // import everything except the log4j package - should not be needed
            instruction 'Import-Package', '!org.apache.log4j', '*'
            instruction 'Bundle-Description', 'c3p0 is an easy-to-use library for making traditional ' +
                    'JDBC drivers "enterprise-ready" by augmenting them with functionality defined by ' +
                    'the jdbc3 spec and the optional extensions to jdbc2.'
        }
    }
    

提交回复
热议问题