【问题标题】:Wrap third party jar that imports from default package using bndtools使用 bndtools 包装从默认包导入的第三方 jar
【发布时间】:2016-04-15 17:33:04
【问题描述】:

我想包装一个第三方罐子。不幸的是,供应商将一个单一的类(a.class)和一个单一的方法放入默认包中。

当我尝试使用Include-Resource: @lib/acme-8.0.jar 包含资源时,会导致以下错误:

The default package '.' is not permitted by the Import-Package syntax.
This can be caused by compile errors in Eclipse because Eclipse creates valid class files regardless of compile errors.
The following package(s) import from the default package [com.acme.util]

bnd print -all acme-8.0.jar 给我以下输出(缩短,供应商名称替换为 acme)

[API USES]
.                                        []

com.acme.common                            []

com.acme.acmedrt                             [com.acme.acmedrt.types, com.acme.acmedrt.comm.jobtransport, com.acme.acmedrt.workflow.type
s]

com.acme.acmedrt.impl                        [com.acme.acmedrt, com.acme.acmedrt.types, org.apache.commons.logging, com.acme.acmedrt.imp
l.types, com.acme.acmedrt.comm.jobtransport, com.acme.acmedrt.pool, org.apache.commons.pool, com.acme.acmedrt.workflow.types]

com.acme.acmedrt.impl.types                  [com.acme.acmedrt.types, com.acme.acmedrt, com.acme.acmedrt.impl, org.xml.sax]

com.acme.acmedrt.notification                [com.acme.acmedrt]

com.acme.acmedrt.pool                        [com.acme.acmedrt, com.acme.acmedrt.impl.types, com.acme.acmedrt.impl, com.acme.acmedrt.types,
org.apache.commons.pool, com.acme.acmedrt.workflow.types]

com.acme.acmedrt.types                       [com.acme.acmedrt, com.acme.common]

com.acme.acmedrt.util                        []

com.acme.acmedrt.workflow.types              [com.acme.common]

com.acme.tools                             []

com.acme.util                              []

com.acme.util.xml                          []


[LIST]

  a.class
META-INF
  MANIFEST.MF
com
com <no contents>
com/acme
com/acme <no contents>
com/acme/common
  Enum.class
com/acme/acmedrt
[...]

如果我正确理解此输出,则有几个包使用默认包。这怎么可能呢?据我所知,您不能从默认包中导入类。

我已经联系了供应商,要求移动违规班级。很有可能,他不会听从我的建议。

是否有解决方法来处理默认包中的类?

【问题讨论】:

  • 在OSGi中不能导入默认包是真的。但是在你的包中包含默认包中的类应该没问题。
  • @NeilBartlett 也许,但是 bnd 无法从给定的 jar 创建一个包,导致上面的错误消息。
  • 看起来该类是默认包,在其他包的API中被引用。因此出现错误消息。
  • @BJHargrave 我同意。但正如我所说,我对第三方 jar 没有任何控制权。有没有办法在不更改给定 jar 的情况下解决此错误并创建捆绑包?
  • 如果你不能将类移动到一个命名的包中,那么你就不能从 jar 中制作一个包。未命名的(默认)包无法导出或导入。

标签: java jar osgi bnd bndtools


【解决方案1】:

您可能可以选择以下选项:

 -fixupmessages: "The default package "

【讨论】:

  • 此选项会抑制错误消息并使我能够创建捆绑包。但是,在某些情况下,使用该库会导致异常(“com/acme/util/a.a(I)Ljava/lang/String;@44: if_icmpge .Expected stackmap frame at this location.”)。不知道这是否与默认包中缺少的类有关,还是依赖不满足的结果。
  • 查看消息这不太可能但并非不可能......但是如果你有一个糟糕的图书馆,你就会遇到糟糕的问题...... :-(
  • 供应商对其库的某些部分使用代码混淆。调用混淆代码时似乎会发生上述错误。我联系了供应商以审查他们的产品。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-26
  • 2012-07-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多