我们在 Weblogic 10.3 上运行的 Web 应用程序中遇到了一个非常奇怪的 class not found 问题。在我们的代码中,我们做了一个非常标准的 XSLT 转换。
UtilRequestManagerBean.java:
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource(new StringReader(xslBuffer.toString())));
transformer.transform(new StreamSource(new StringReader(sourceBuffer.toString())), new StreamResult(sw));
这在我们的生产环境(Solaris 10,如果这很重要)中失败并产生 java.lang.NoClassDefFoundError:
<Mar 11, 2010 1:44:08 PM EET> <Info> <EJB> <BEA-010227> <EJB Exception occurred during invocation from home or business: com.company.basicservice.ejb.util.UtilRequestManagerBean_temuyq_HomeImpl@1737be7 threw exception: java.lang.NoClassDefFoundError: Could not initialize class com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary>
这个类是 rt.jar 的一部分,并且肯定在类路径中。这由以下 Weblogic 日志片段验证:
sun.boot.class.path = /opt/jdk1.6.0_12/jre/lib/resources.jar:/opt/jdk1.6.0_12/jre/lib/rt.jar:/opt/jdk1.6.0_12/jre/lib/sunrsasign.jar:/opt/jdk1.6.0_12/jre/lib/jsse.jar:/opt/jdk1.6.0_12/jre/lib/jce.jar:/opt/jdk1.6.0_12/jre/lib/charsets.jar:/opt/jdk1.6.0_12/jre/classes
最后列出 rt.jar 的内容表明该类存在:
jar tvf /opt/jdk1.6.0_12/jre/lib/rt.jar | grep BasisLibrary.class
24787 Sat Jan 17 02:25:58 EET 2009 com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.class
那么,这里到底有什么问题呢?