我想在我的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>
解决了这个问题,但我不明白,为什么在core-3.3.2.jar
和*
访问外部jar-1(Zxing:**
)并且能够很好地访问外部jar-2 (Zxing:javase-3.3.2.jar
)在67
没有。
我不想影响容器类加载策略。
答案 0 :(得分:0)
由于tsolakp假设正确,java.lang.LinkageError
的原因是com.google.zxing.common.BitMatrix
的两个版本。错误地,我将同一个jar放在${domain_dir}/lib
和EARContent/lib
中。