Good way to “wrap” jars for OSGi with Maven

后端 未结 4 1704
名媛妹妹
名媛妹妹 2021-02-10 03:32

I was looking at the PAX tools on OPS4J for example: this one and I thought I\'d found a nice way to:

  • Specify an artifact
  • Create an assembled jar (jar tha
相关标签:
4条回答
  • 2021-02-10 04:14

    We do something similar to what you are describing. For example, we have an internal version of Apache QPid. It comes as 6 jars (client, core, common, backports, etc) which you would rarely use individually. We have one POM with BND which takes all the jars, and makes one uber-osgi-jar from them.

    Steps:

    1. Declare your dependencies (we have the jars, so we declared them as system deps.)
    2. Import build plugin maven-bundle-plugin (2.1.0)
    3. Set correct instructions for export, private and import packages
    4. Execution of 'wrap' goal at 'package' phase
    0 讨论(0)
  • 2021-02-10 04:25

    You have to maintain a local POM to get this done. There's not a utility that will take in a library/jar and spit out the appropriate OSGi MANIFEST in a jar. ServiceMix, along with Spring, have a lot of things already bundled up that you can use as examples. Two such examples I suggest looking at are:

    • commons-io - simple library wrapper
    • OpenJPA - wraps the main jar and brings in the dependencies with it
    0 讨论(0)
  • 2021-02-10 04:28

    I wrote a maven archetype that will help you wrap a jar as an OSGI bundle.

    Let's say you want to wrap commons-collections version 3.2.1

    First get the archetype and install it

    git clone git://github.com/HallwayTech/maven-wrap-jar-archetype.git 
    cd maven-wrap-jar-archetype
    maven install
    

    Then use the archetype to start your project.

    mvn archetype:create \
      -DarchetypeGroupId=com.hallwaytech.osgi \
      -DarchetypeArtifactId=wrap-jar \
      -DarchetypeVersion=1.0-SNAPSHOT \
      -DgroupId=commons-collections \
      -DartifactId=commons-collections \
      -Dversion=3.2.1
    

    cd commons-collections

    mvn install
    

    To deploy to a Apache Sling inside of Felix run:

    mvn install -Pdeploy
    
    0 讨论(0)
  • 2021-02-10 04:33

    I tried The accepted answer and Erik's answer. Erik's suggestion was simple and worked right out the box. Although, it seemed to produce a huge MANIFEST in my case, and then I recalled the p2-maven-plugin. This last method works very well in a large number of cases. If the artifact you need is already bundle, or its dependencies are bundles it simply puts them into the repo it builds. If not, it will run maven-bundle-plugin with some default settings (or you can configure the settings you need). Very cool!

    I especially like that it grabs the transitive dependencies and takes care of those too. If you don't need the repo, but are just after the wrapped bundle, it is a simple matter to go cherry pick it out of target/repository/plugins folder.

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