我个人非常喜欢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.
Create a new Plug-in project from existing JAR archive.
Add the jar file to be exported
Click next and name the project.
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.
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.
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.'
}
}
发布评论
评论(6)
如果您使用的是 eclipse:有一个向导。
它允许您选择多个 jar 库并创建包含这些 jar 的插件项目(即 OSGi 包)。
您可以在这里找到它:
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:
原则上,您只需将 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.
首先检查是否可以从
如果没有找到支持 OSGi 的版本。您可以继续使用 pax 工具 - PaxConstruct 或使用 aQute 的 Bnd 工具。
First check out if you can find a osgi enabled version of your library from repositories
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.
将 JAR 存档解压到项目已取消选择< /em>->取消选择它,将导出 JAR 的所有包
如果将 JAR 存档解压到项目中被选中,那么您将需要手动导出< strong>MANIFEST.MF 文件。
单击完成。您将发现在工作区中创建了名为“transport-5.1.1”的项目。您还可以验证,JAR 的所有包都导出到 MANIFEST.MF 文件中。
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.
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.
迟到:
如果您使用 Gradle,如果应用 osgi-run 插件。
osgi-run 插件会将 jar 透明地打包成一个包,导出其中的每个包并计算其所有导入。由于 Gradle 会知道 jar 的传递依赖项,因此如有必要,它也会对它们执行相同的操作。
jar 将成为 osgi-run 创建的 OSGi 运行时的一部分,然后您可以使用 gradle runOsgi 或 gradle createOsgi 启动它,然后执行>run.sh 或
run.bat
脚本。实际的包装是由 OSGi 世界的瑞士刀 Bnd 完成的。
如果您想配置包装如何发生(通常应该导入/导出什么),您可以在 Gradle 构建文件中轻松完成,请参阅 文档 了解详细信息。
例子:
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
orgradle createOsgi
, then executing either therun.sh
orrun.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: