简体   繁体   English

将现有JAR转换为OSGi-bundle

[英]Convert existing JAR to OSGi-bundle

I have a JAR file that I need to convert to an OSGi bundle. 我有一个JAR文件,我需要转换为OSGi包。 I do not have the original source code for the JAR file. 我没有JAR文件的原始源代码。

I tried to use the answers from: How to create OSGi bundle from jar library? 我尝试使用以下答案: 如何从jar库创建OSGi包?

However, they are pretty outdated. 但是,它们已经过时了。

Edit: I need to convert several, but a fixed number of jars. 编辑:我需要转换几个,但固定数量的罐子。

Option 1 - use bnd-platform to build your OSGi bundles when expecting frequent additions/updates of Jars, or when you can retrieve your dependencies from Maven repositories 选项1 - 在期望频繁添加/更新Jars时,或者当您可以从Maven存储库检索依赖项时,使用bnd-platform来构建OSGi包

We use bnd-platform (I am also the author) to manage third party dependencies and create OSGi bundles from them. 我们使用bnd-platform (我也是作者)来管理第三方依赖项并从中创建OSGi包。 You can use it with both dependencies retrieved from Maven repositories and local Jars (see the README ). 您可以将它与从Maven存储库和本地Jars中检索到的两个依赖项一起使用(请参阅自述文件 )。 If you regularly add or update your dependencies I would suggest that you try bnd-platform . 如果您经常添加或更新您的依赖项,我建议您尝试使用bnd-platform It's a plugin for Gradle, you can easily start with this template - just add your Jar files and provide the configuration as described in the project README (bundle symbolic names, versions) and run gradlew bundles . 它是Gradle的插件,您可以轻松地从这个模板开始 - 只需添加您的Jar文件并提供项目README(捆绑符号名称,版本)中所述的配置并运行gradlew bundles

Option 2 - use bnd to build your OSGi bundles when you do it once or additions/updates are seldom 选项2 - 使用bnd在您执行一次或添加/更新很少时构建您的OSGi包

If you only do this process once or seldom, a simple way to create an OSGi bundle from an existing Jar is to directly use bnd on the command line . 如果您只执行此过程一次或很少,从现有Jar创建OSGi包的简单方法是直接在命令行上使用bnd The only thing you need is Java and the bnd jar. 你唯一需要的是Java和bnd jar。 You can use wrap to try to automatically wrap a jar or create a .bnd file with instructions for bnd (eg to only export specific packages). 您可以使用wrap来尝试自动包装jar或创建带有bnd指令.bnd文件(例如,仅导出特定的包)。

Example .bnd file: 示例.bnd文件:

-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

Example call: 示例电话:

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

The bnd Jar download is no longer offered directly through the web site, a good alternative is to download it from Maven Central . 不再直接通过网站提供bnd Jar下载,一个很好的选择是从Maven Central下载它

The Eclipse Bundle Recipe project provides a Maven based approach for adding OSGi meta data to JARs consumed from a Maven repository. Eclipse Bundle Recipe项目提供了一种基于Maven的方法,用于将OSGi元数据添加到从Maven存储库中使用的JAR。 Despite the name it doesn't use Eclipse. 尽管名称它不使用Eclipse。

At its core, it uses the bnd tool . 它的核心是它使用了bnd工具 This tool is like a swiss army knife. 这个工具就像一把瑞士军刀。 It analyzes jars and class files and properly calculate package import and exports. 它分析jar和类文件并正确计算包导入和导出。 You should use bnd for converting proprietary jars yourself. 你应该使用bnd自己转换专有的罐子。 It's available in Maven Central . 可以在Maven Central中找到

If you're using Maven then you can use the Maven Bundle Plugin to inline or embed dependencies in a OSGi bundle: 如果您正在使用Maven,那么您可以使用Maven Bundle插件在OSGi包中内联或嵌入依赖项:

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

or just use osgi:install with wrap option as below. 或者只使用osgi:install with wrap选项,如下所示。

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

this will deploy the jar file as bundle and you can get the bundle under "$fuse_home/data/cache/bundle{id}/version0.0" folder. 这将把jar文件部署为bundle,你可以在“$ fuse_home / data / cache / bundle {id} /version0.0”文件夹下获得该包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM