Wrap third party jar that imports from default package using bndtools

半世苍凉 提交于 2019-12-11 22:06:27

问题


I want to wrap a third party jar. Unfortunately the vendor placed one single class (a.class) with one single method into the default package.

When I try to include the resource using Include-Resource: @lib/acme-8.0.jar, it results in the following error:

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 gives me the following output (shortened, vendor name replaced with 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
[...]

If I understand this output correctly, several packages use the default package. How is that even possible? As far is I know, you can not import classes from the default package.

I already contacted the vendor with the request to move the offending class. Chances are, that he will not follow my suggestion.

Is there a workaround to handle classes in the default package?


回答1:


You probably can get away with the following option:

 -fixupmessages: "The default package "


来源:https://stackoverflow.com/questions/34721015/wrap-third-party-jar-that-imports-from-default-package-using-bndtools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!