OSGi 包清单中的包类路径的字符限制?

发布于 2024-09-11 15:56:22 字数 618 浏览 12 评论 0原文

使用 Apache Felix,我编写了一个 OSGi 组件,它包装了我公司使用的一些中间件。目前它依赖于大量的外部库,而且我似乎遇到了 Bundle-classpath 的限制:参数长度。我不得不将 commons-collections.jar 等库重命名为 ccoll.jar。

我很好奇是否有人对解决此限制有任何建议?

Bundle-ClassPath: .,lib/log4j.jar,lib/cvfs.jar,lib/backport.jar,lib/cbeanutils.jar,lib/ccodec.jar,lib/ccoll.jar,lib/chttp.jar,lib/cjxpath.jar,lib/clang.jar,[libs redacted],lib/saaj-api.jar,lib/saaj-impl.jar,lib/Schemas.jar,lib/xbean.jar,lib/clog.jar,lib/dom4j.jar,lib/xml-apis.jar,lib/xerces.jar,lib/xalan.jar,lib/jaxp-ri.jar,lib/japi.jar,lib/mail.jar

我想我可以通过省略 lib/ 位来获得更多字符,但我很好奇这是一个错误、一个定义的限制,还是只是我的白痴。

Using Apache Felix, I have an OSGi component I've authored that wraps some middleware my company uses. Currently it depends on a good number of external libraries, and I appear to have run into a limit on the Bundle-classpath: parameter length. I've had to rename libraries such as commons-collections.jar to ccoll.jar.

I'm curious if anyone has any advice on working around this limitation?

Bundle-ClassPath: .,lib/log4j.jar,lib/cvfs.jar,lib/backport.jar,lib/cbeanutils.jar,lib/ccodec.jar,lib/ccoll.jar,lib/chttp.jar,lib/cjxpath.jar,lib/clang.jar,[libs redacted],lib/saaj-api.jar,lib/saaj-impl.jar,lib/Schemas.jar,lib/xbean.jar,lib/clog.jar,lib/dom4j.jar,lib/xml-apis.jar,lib/xerces.jar,lib/xalan.jar,lib/jaxp-ri.jar,lib/japi.jar,lib/mail.jar

I suppose I could get more characters by leaving off the lib/ bits, but I'm curious if this is a bug, a defined limitation, or just simply idiocy on my part.

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

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

发布评论

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

评论(5

书间行客 2024-09-18 15:56:22

清单行长度限制为 72 个字节,如 http: //java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html。之后,您必须拆分该行并以空格字符开始新的一行。在这种情况下:

Bundle-ClassPath: .,lib/log4j.jar,lib/cvfs.jar,lib/backport.jar,lib/cbea
 nutils.jar,lib/ccodec.jar,lib/ccoll.jar,lib/chttp.jar,lib/cjxpath.jar,l
 ib/clang.jar,[libs redacted],lib/saaj-api.jar,lib/saaj-impl.jar,lib/Sch
 emas.jar,lib/xbean.jar,lib/clog.jar,lib/dom4j.jar,lib/xml-apis.jar,lib/
 xerces.jar,lib/xalan.jar,lib/jaxp-ri.jar,lib/japi.jar,lib/mail.jar

或者,您可以使用 BND 之类的工具,它会自动为您执行类似的操作(以及更多操作)。

Manifest line lengths are limited to 72 bytes as stated in http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html. After that you will have to split the line and start a new one beginning with a space character. In this case:

Bundle-ClassPath: .,lib/log4j.jar,lib/cvfs.jar,lib/backport.jar,lib/cbea
 nutils.jar,lib/ccodec.jar,lib/ccoll.jar,lib/chttp.jar,lib/cjxpath.jar,l
 ib/clang.jar,[libs redacted],lib/saaj-api.jar,lib/saaj-impl.jar,lib/Sch
 emas.jar,lib/xbean.jar,lib/clog.jar,lib/dom4j.jar,lib/xml-apis.jar,lib/
 xerces.jar,lib/xalan.jar,lib/jaxp-ri.jar,lib/japi.jar,lib/mail.jar

Alternatively you could use a tool like BND that does things like this (and more) for you automatically.

凉风有信 2024-09-18 15:56:22

正如莫里茨所说每行 72 字节限制

Java jar 包包括用于编写清单的代码:

Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
attributes
    .putValue(
        "Bundle-Classpath",
        "<snip>");
manifest.write(System.out);

注意:Manifest-Version 是强制性的。

这会产生输出:

Manifest-Version: 1.0
Bundle-Classpath: .,lib/log4j.jar,lib/cvfs.jar,lib/backport.jar,lib/cb
 eanutils.jar,lib/ccodec.jar,lib/ccoll.jar,lib/chttp.jar,lib/cjxpath.j
 ar,lib/clang.jar,[libsredacted],lib/saaj-api.jar,lib/saaj-impl.jar,li
 b/Schemas.jar,lib/xbean.jar,lib/clog.jar,lib/dom4j.jar,lib/xml-apis.j
 ar,lib/xerces.jar,lib/xalan.jar,lib/jaxp-ri.jar,lib/japi.jar,lib/mail
 .jar

There is, as Moritz says, a 72-byte limit per line.

The Java jar package includes code for writing manifests:

Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
attributes
    .putValue(
        "Bundle-Classpath",
        "<snip>");
manifest.write(System.out);

Note: Manifest-Version is mandatory.

This produces the output:

Manifest-Version: 1.0
Bundle-Classpath: .,lib/log4j.jar,lib/cvfs.jar,lib/backport.jar,lib/cb
 eanutils.jar,lib/ccodec.jar,lib/ccoll.jar,lib/chttp.jar,lib/cjxpath.j
 ar,lib/clang.jar,[libsredacted],lib/saaj-api.jar,lib/saaj-impl.jar,li
 b/Schemas.jar,lib/xbean.jar,lib/clog.jar,lib/dom4j.jar,lib/xml-apis.j
 ar,lib/xerces.jar,lib/xalan.jar,lib/jaxp-ri.jar,lib/japi.jar,lib/mail
 .jar
把时间冻结 2024-09-18 15:56:22

另外,考虑将第三方库打包在自己的包中,有些甚至是 osgi 就绪的。

Also, consider packaging third-party libraries in their own bundles, some are even osgi-ready.

千寻… 2024-09-18 15:56:22

看看 Apache 的 http://wiki.apache.org/commons/CommonsOsgi - Commons OSGi 就绪库。否则请查看 http://www.springsource.com/repository/app/ 如果它们已经捆绑了您的第 3 方库。

独立安装这些捆绑包,不要将它们嵌入到您的捆绑包中。

Have a look at http://wiki.apache.org/commons/CommonsOsgi for Apache-Commons OSGi ready libraries. Otherwise look at http://www.springsource.com/repository/app/ if they bundled your 3rd party library already.

Install these bundles independent and do not embed them in your bundle.

流殇 2024-09-18 15:56:22

首先,永远不要直接编辑MANIFEST.MF。在标准文本文件(例如 mymanifest.txt)中对其进行编辑,然后传递给 jar 命令,如下所示:

jar cfm output.jar mymanifest.txt <other files>

jar 工具将插入根据需要换行。

更好的答案:使用 Peter Kriens 的 Bnd 工具生成您的显现。

另外,正如其他评论者指出的那样,最好将这些库用作 OSGi 捆绑包。将所有依赖项放入一个包中有点忽略了 OSGi 的意义。

First, never directly edit MANIFEST.MF. Edit it in a standard text file, for example mymanifest.txt, then pass to the jar command as follows:

jar cfm output.jar mymanifest.txt <other files>

The jar tool will then insert the line-wraps as necessary.

Better answer: use the Bnd tool by Peter Kriens to generate your manifest.

Also as other commenters have pointed out, it is much better to use these libraries as OSGi bundles. Sticking all of your dependencies into one bundle is kind of missing the point of OSGi.

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