将现有的 JAR 转换为 OSGi-bundle [英] Convert existing JAR to OSGi-bundle

查看:21
本文介绍了将现有的 JAR 转换为 OSGi-bundle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我尝试使用以下答案:如何创建 OSGi 包来自 jar 库?

但是,它们已经过时了.

However, they are pretty outdated.

我需要转换几个固定数量的罐子.

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

推荐答案

选项 1 - 使用 bnd-platform 在期望频繁添加/更新罐子,或者当你可以从 Maven 存储库中检索你的依赖项

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

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

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.

选项 2 - 使用 bnd 构建您的 OSGi 包,当您只做一次或很少添加/更新时

Option 2 - use bnd to build your OSGi bundles when you do it once or additions/updates are seldom

如果您只执行一次或很少执行此过程,从现有 Jar 创建 OSGi 包的一种简单方法是直接使用 bnd 在命令行上.您唯一需要的是 Java 和 bnd jar.您可以使用 wrap 尝试自动包装 jar 或使用 bnd 的说明(例如只导出特定的包).

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 wrap to try to automatically wrap a jar or create a .bnd file with instructions for bnd (e.g. to only export specific packages).

示例 .bnd 文件:

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

示例调用:

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

不再直接通过网站提供 bnd Jar 下载,一个不错的选择是 从Maven Central下载.

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

这篇关于将现有的 JAR 转换为 OSGi-bundle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆