我想在我的ejb bean中使用外部jars (Zxing,Batik),根据this thread的说法,我将jars添加到了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)能很好地工作,而在67上访问外部jar-2 (Zxing:javase-3.3.2.jar)就不行了。
我不希望影响容器的类加载策略。
发布于 2018-02-12 02:14:25
正如tsolakp假设的那样,java.lang.LinkageError的原因是com.google.zxing.common.BitMatrix的两个版本。错误地,我将相同的jar放在了${domain_dir}/lib和EARContent/lib中。
https://stackoverflow.com/questions/48712974
复制相似问题