How to create OSGi bundle from jar library?
Asked Answered
P

6

21

How to create OSGi bundle from jar library?

Pigskin answered 29/8, 2010 at 8:8 Comment(1)
This question is related.Unpaid
N
30

In case you are using eclipse: There is a wizard for that.

It allows you to select a number of jar libraries and creates a plug-in project (i.e. OSGi bundle) including these jars.

You can find it here:

File -> New -> Other ... -> Plug-in from Existing jar Archives.

alt text

Navarrette answered 29/8, 2010 at 12:22 Comment(2)
+1 because the own OP didn't vote it up :( (if it's correct then vote it up!)Thundering
That wizard screenshot is enough. Thanks!Kiel
F
10

In principle you just need to add OSGi metadata to the manifest

There is a bundle creator for eclipse which gives a very practical way to add these entries which should be part of the Plugin Dev Toolkit.

Here is an article detailing the process and how to do it with the Bnd tool, maven and so forth.

I personally like the pax tools very much. It is all command line based, but very practical. To create an OSGi bundle of an existing jar you can use bnd tool.

Fates answered 29/8, 2010 at 8:58 Comment(1)
pax tools and pax-wrap-jar links are deadShack
K
6

First check out if you can find a osgi enabled version of your library from repositories

  1. SpringSource http://www.springsource.com/repository
  2. Fusesource http://repo.fusesource.com/

If you don't find the OSGi enabled versions. You can go ahead with using the pax tool - PaxConstruct or use the aQute's Bnd tool.

Kenleigh answered 29/8, 2010 at 9:10 Comment(4)
@Shack Thanks, I updated the links to more recent resources.Fates
@PeterTillemans , which links did you update? Unfortunately, I don't know what's fusesource new repo URL is.. please feel free to links in my answerKenleigh
@Abdel Sorry, I put the comment to the wrong answer. I updated the links of the pax tools and bnd tool in my answer. Fusesource has been bought by redhat, so I assume they have merged the fusesource repo to the redhat repository.Fates
The fusesource link is dead again.Merit
P
3
  • Create a new Plug-in project from existing JAR archive.

enter image description here

  • Add the jar file to be exported

enter image description here

  • Click next and name the project.

enter image description here

  • NOTE:
  • Make sure OSGI framework is selected in target platform.
  • Unzip the JAR archives into the project is deselected -> deselecting it, will export all the packages of the JAR

  • if Unzip the JAR archives into the project is selected then you will manually need to export required packages in the MANIFEST.MF file.

Click finish. You will find project with name transport-5.1.1 created in your workspace. Also you can verify, all the packages of the JAR are exported in MANIFEST.MF file.

Pinchas answered 16/12, 2016 at 6:33 Comment(0)
H
2

The Eclipse Bundle Recipe project provides a Maven based approach for adding OSGi meta data to JARs consumed from a Maven repository.

At its core, it uses the bnd tool. This tool is like a swiss army knife. It analyzes jars and class files and properly calculate package import and exports. You should use bnd for converting proprietary jars yourself. It's available in Maven Central.

Hasheem answered 8/4, 2015 at 11:49 Comment(0)
F
1

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.'
    }
}
Fula answered 8/4, 2016 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.