如何从 jar 库创建 OSGi 包?

发布于 2024-09-16 13:29:09 字数 26 浏览 9 评论 0 原文

如何从 jar 库创建 OSGi 包?

How to create OSGi bundle from jar library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

仅一夜美梦 2024-09-23 13:29:09

如果您使用的是 eclipse:有一个向导。

它允许您选择多个 jar 库并创建包含这些 jar 的插件项目(即 OSGi 包)。

您可以在这里找到它:

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

alt text

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

烛影斜 2024-09-23 13:29:09

原则上,您只需将 OSGi 元数据添加到清单中。

Eclipse 有一个包创建器,它提供了一种非常实用的方法来添加这些条目,这些条目应该是插件开发工具包的一部分。

这是一篇 文章 详细介绍了该过程以及如何操作它与Bnd工具、maven等等。

我个人非常喜欢pax 工具。它都是基于命令行的,但非常实用。要创建现有 jar 的 OSGi 捆绑包,您可以使用 bnd 工具

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.

冷默言语 2024-09-23 13:29:09

首先检查是否可以从

  1. SpringSource 存储库中找到支持 osgi 的库版本 http://www.springsource.com /repository
  2. Fusesource http://repo.fusesource.com/

如果没有找到支持 OSGi 的版本。您可以继续使用 pax 工具 - PaxConstruct 或使用 aQute 的 Bnd 工具

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.

银河中√捞星星 2024-09-23 13:29:09
  • 从现有 JAR 存档创建一个新的插件项目。

输入图片这里的描述

  • 添加要导出的jar文件

在此处输入图像描述

  • 单击“下一步”并为项目命名。

输入图片此处描述

  • 注意:
  • 确保在目标平台中选择了 OSGI 框架。
  • 将 JAR 存档解压到项目已取消选择< /em>->取消选择它,将导出 JAR 的所有包

  • 如果将 JAR 存档解压到项目中选中,那么您将需要手动导出< strong>MANIFEST.MF 文件。

单击完成。您将发现在工作区中创建了名为“transport-5.1.1”的项目。您还可以验证,JAR 的所有包都导出到 MANIFEST.MF 文件中。

  • 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.

狂之美人 2024-09-23 13:29:09

Eclipse Bundle Recipe 项目提供了一种基于 Maven 的方法,用于将 OSGi 元数据添加到从 Maven 存储库使用的 JAR 。

它的核心是使用 bnd 工具。这个工具就像一把瑞士军刀。它分析 jar 和类文件并正确计算包导入和导出。您应该使用 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.

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.

影子是时光的心 2024-09-23 13:29:09

迟到:

如果您使用 Gradle,如果应用 osgi-run 插件。

osgi-run 插件会将 jar 透明地打包成一个包,导出其中的每个包并计算其所有导入。由于 Gradle 会知道 jar 的传递依赖项,因此如有必要,它也会对它们执行相同的操作。

jar 将成为 osgi-run 创建的 OSGi 运行时的一部分,然后您可以使用 gradle runOsgi 或 gradle createOsgi 启动它,然后执行>run.sh 或 run.bat 脚本。

实际的包装是由 OSGi 世界的瑞士刀 Bnd 完成的。

如果您想配置包装如何发生(通常应该导入/导出什么),您可以在 Gradle 构建文件中轻松完成,请参阅 文档 了解详细信息。

例子:

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.'
    }
}

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.'
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文