OSGi 包清单中的包类路径的字符限制?
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
清单行长度限制为 72 个字节,如 http: //java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html。之后,您必须拆分该行并以空格字符开始新的一行。在这种情况下:
或者,您可以使用 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:
Alternatively you could use a tool like BND that does things like this (and more) for you automatically.
正如莫里茨所说 、 每行 72 字节限制。
Java jar 包包括用于编写清单的代码:
注意:
Manifest-Version
是强制性的。这会产生输出:
There is, as Moritz says, a 72-byte limit per line.
The Java jar package includes code for writing manifests:
Note:
Manifest-Version
is mandatory.This produces the output:
另外,考虑将第三方库打包在自己的包中,有些甚至是 osgi 就绪的。
Also, consider packaging third-party libraries in their own bundles, some are even osgi-ready.
看看 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.
首先,永远不要直接编辑
MANIFEST.MF
。在标准文本文件(例如mymanifest.txt
)中对其进行编辑,然后传递给jar
命令,如下所示:jar
工具将插入根据需要换行。更好的答案:使用 Peter Kriens 的 Bnd 工具生成您的显现。
另外,正如其他评论者指出的那样,最好将这些库用作 OSGi 捆绑包。将所有依赖项放入一个包中有点忽略了 OSGi 的意义。
First, never directly edit
MANIFEST.MF
. Edit it in a standard text file, for examplemymanifest.txt
, then pass to thejar
command as follows: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.