java 将现有的 JAR 转换为 OSGi-bundle

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29494485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 15:23:05  来源:igfitidea点击:

Convert existing JAR to OSGi-bundle

javaintellij-ideaosgiosgi-bundle

提问by CodeTower

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

我有一个 JAR 文件,需要将其转换为 OSGi 包。我没有 JAR 文件的原始源代码。

I tried to use the answers from: How to create OSGi bundle from jar library?

我尝试使用以下答案:How to create OSGi bundle from jar library?

However, they are pretty outdated.

然而,它们已经过时了。

Edit:I need to convert several, but a fixed number of jars.

编辑:我需要转换几个,但固定数量的罐子。

采纳答案by stempler

Option 1- use bnd-platformto build your OSGi bundles when expecting frequent additions/updates of Jars, or when you can retrieve your dependencies from Maven repositories

选项 1- 使用bnd-platform来构建您的 OSGi 包,当您期望频繁添加/更新 Jars 时,或者您可以从 Maven 存储库中检索您的依赖项时

We use bnd-platform(I am also the author) to manage third party dependencies and create OSGi bundles from them. You can use it with both dependencies retrieved from Maven repositories and local Jars (see the README). If you regularly add or update your dependencies I would suggest that you try 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.

我们使用bnd-platform(我也是作者)来管理第三方依赖项并从中创建 OSGi 包。您可以将它与从 Maven 存储库和本地 Jars 检索的依赖项一起使用(请参阅自述文件)。如果您定期添加或更新您的依赖项,我建议您尝试bnd-platform。它是 Gradle 的一个插件,您可以轻松地从这个模板开始- 只需添加您的 Jar 文件并提供项目 README(捆绑符号名称、版本)中所述的配置并运行gradlew bundles.

Option 2- use bndto 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. The only thing you need is Java and the bnd jar. You can use wrapto try to automatically wrap a jar or create a .bndfile with instructions for bnd(e.g. to only export specific packages).

如果您只执行一次或很少执行此过程,从现有 Jar 创建 OSGi 包的一种简单方法是直接在命令行上使用bnd。您唯一需要的是 Java 和 bnd jar。您可以使用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 下载

回答by Gunnar

The Eclipse Bundle Recipeproject provides a Maven based approach for adding OSGi meta data to JARs consumed from a Maven repository. Despite the name it doesn't use Eclipse.

Eclipse的包配方项目为添加的OSGi元数据从Maven仓库所消耗的JAR一个Maven为基础的方法。尽管名称,它不使用 Eclipse。

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.

它的核心是使用bnd 工具。这个工具就像一把瑞士军刀。它分析 jars 和类文件并正确计算包的导入和导出。您应该使用 bnd 自己转换专有 jars。它在 Maven Central 中可用

回答by Puce

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 Plugin 在 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

回答by vedat

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

或者只是使用 osgi:install 和 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 文件部署为包,您可以在“$fuse_home/data/cache/bundle{id}/version0.0”文件夹下获取包。