Convert existing JAR to OSGi package

I have a JAR file that I need to convert to an OSGi package. I do not have the source code for the JAR file.

I tried using answers from: How to create an OSGi package from jar library?

However, they are quite outdated.

Edit: I need to convert a few, but a fixed number of cans.

+6
source share
4 answers

Option 1 - use the bnd platform to build OSGi packages when you expect frequent additions / updates to Jars or when you can get your dependencies from Maven repositories

We use bnd-platform (I am also the author) to manage third-party dependencies and create OSGi packages. You can use it with two dependencies derived from Maven repositories and local Jars (see README ). If you regularly add or update your dependencies, I suggest you try bnd-platform. This is a plugin for Gradle, you can easily start with this template - just add Jar files and provide the configuration as described in the README project (combine symbolic names, versions) and run gradlew bundles .

Option 2 - use bnd to build OSGi packages when you do it once, or rarely add or update

If you perform this process only once or simply, an easy way to create an OSGi package from an existing Jar is to use bnd directly on the command line . The only thing you need is Java and bnd jar. You can use wrap to try to automatically wrap the jar or create a .bnd file using the instructions for bnd (for example, only to export specific packages).

Example .bnd file:

 -classpath: lib/trove-2.0.4.jar -output: gnu.trove-2.0.4.jar Export-Package: *;-split-package:=merge-last;-noimport:=true Import-Package: * Bundle-Version: 2.0.4 Bundle-Name: GNU Trove Collections Plug-in Bundle-SymbolicName: gnu.trove 

Call example:

 java -jar <path to bnd>.jar trove-2.0.4.bnd 

Downloading the bnd Jar is no longer offered directly through the website, a good alternative is to download it from Maven Central .

+6
source

The Eclipse Bundle Recipe project provides a Maven-based approach for adding OSGi metadata to JARs used in the Maven repository. Despite the name, it does not use Eclipse.

At its core, it uses the bnd tool. This tool is similar to a Swiss army knife. It analyzes banks and class files and correctly calculates import and export packages. You must use bnd to convert your own banks yourself. It is available at Maven Central .

+2
source

If you use Maven, you can use the Maven Bundle Plugin for inline or inline dependencies in the OSGi bundle:

http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html#embedding-dependencies

+2
source

or just use the osgi: install with wrap option, as shown below.

 osgi:install wrap:file:/u01/repository/com/oracle/ojdbc6/11.2.0/ojdbc6-11.2.0.jar 

this will expand the jar file as a package, and you can get the package in the $ fuse_home / data / cache / bundle {id} /version0.0 folder.

0
source

Source: https://habr.com/ru/post/984795/


All Articles