【发布时间】:2018-02-09 19:38:43
【问题描述】:
我想在我的 ejb bean 中使用外部罐子(Zxing、Batik),根据this thread 我将罐子添加到EarContent/lib,一切似乎都很好。我的 ejb-bean 看起来像:
@Stateless
public class ManageBarcodeBean implements ...{
...
@Override
public String createQrCode(String text, Dimension dim, ErrorCorrectionLevel errCorr) {
...
try {
...
if (Math.max(dim.getWidth(), dim.getHeight()) <= 1000) {
//*
QRCodeWriter qrCodeWriter = new QRCodeWriter();
//**
BitMatrix bm = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, dim.getWidth(), dim.getHeight(), hints);
//67
BufferedImage imgBuf = MatrixToImageWriter.toBufferedImage(bm);
...
}
...
} catch (Exception e) {
...
}
return null;
}
...
}
直到我添加行 \\ 67 一切正常,但添加此行会产生:
Caused by: java.lang.LinkageError:
loader constraint violation:
when resolving method
"com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(Lcom/google/zxing/common/BitMatrix;)Ljava/awt/image/BufferedImage;"
the class loader (instance of org/glassfish/javaee/full/deployment/EarClassLoader)
of the current class, de/lsanet/lav/address/beans/ManageBarcodeBean,
and the class loader (instance of com/sun/enterprise/loader/CurrentBeforeParentClassLoader)
for the method's defining class, com/google/zxing/client/j2se/MatrixToImageWriter,
have different Class objects for the type com/google/zxing/common/BitMatrix
used in the signature at
de.lsanet.lav.address.beans.ManageBarcodeBean.createQrCode(ManageBarcodeBean.java:67)
我找到了this payara solution 并添加了
<classloading-delegate>false</classloading-delegate>
解决了这个问题,但我不明白,为什么在* 和** 访问外部jar-1(Zxing:core-3.3.2.jar)工作得很好并访问外部jar-2(Zxing:javase-3.3.2.jar ) 67 没有。
我不希望影响容器类加载策略。
【问题讨论】:
-
您很可能在多个 jar 中拥有不同版本的
com.google.zxing.common.BitMatrix类。 -
我查了一下,只有一个
com.google.zxing.common.BitMatrix,在core-3.3.2.jar中 -
@tsolakp:对不起,你说的完全正确。我搜索了
CurrentBeforeParentClassLoader.java的源代码,在cmets中找到了...this class is needed to allow overriding App Server's Modules / JAR files by placing them into &lt;domain_dir&gt;/lib or EAR lib directory ...,这提醒了我,我的第一个想法是将罐子放在domain_dir/lib,但后来切换到EARContent/lib。我从 domain_dir 中删除了core-3.3.2.jar,但错误地,javase-3.3.2.jar仍然存在并导致我的问题。所以,你的评论就是答案。 -
我很乐意提供帮助。如果有人有同样的问题,您可以从 cmets 为社区创建答案,或者我可以为您解决。
标签: java ejb zxing ear java-ee-7