厉8580 发表于 2016-8-12 06:04:21

第二次被CXF+Oracle Weblogic11g 折磨

Tomcat上调试好的程序发布到weblogic上,又碰到jar包问题.
问题现象1

Invocation of init method failed; nested exception is java.lang.LinkageError:
loader constraint violation: when resolving field "DATETIME" the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader)
of the referring class, javax/xml/datatype/DatatypeConstants, and the class loader (instance of <bootloader>) for the field's resolved type,
javax/xml/namespace/QName, have different Class objects for that type

分析:工程之前已经设置weblogic.xml优先用web/lib下面的包

<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>

"javax/xml/namespace/QName"无法识别这个错误之前已经碰到过,因为 Apache CXF 里的类的时间晚于 Weblogic 里的类的时间,而且类的二进制内容也发生了改变,
于是原来 Weblogic 里的其它类由于我们通过了 prefer-web-inf-classes 设置为 true 后,而引用到了现在的 Apache CXF 里的类了,就发生了 java.lang.LinkageError 错误。
解决方式是把工程下所有带javax/xml/namespace/QName class的都删除掉。
问题现象2.

Caused by: javax.xml.bind.JAXBException
- with linked exception:
[com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
org.w3c.dom.Element is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at org.w3c.dom.Element
at public java.util.List com.sun.xml.ws.developer.MemberSubmissionEndpointReference$Elements.elements
at com.sun.xml.ws.developer.MemberSubmissionEndpointReference$Elements
at public com.sun.xml.ws.developer.MemberSubmissionEndpointReference$Elements com.sun.xml.ws.developer.MemberSubmissionEndpointRefer
ence.referenceProperties
at com.sun.xml.ws.developer.MemberSubmissionEndpointReference
org.w3c.dom.Element does not have a no-arg default constructor.
this problem is related to the following location:
at org.w3c.dom.Element
at public java.util.List com.sun.xml.ws.developer.MemberSubmissionEndpointReference$Elements.elements
at com.sun.xml.ws.developer.MemberSubmissionEndpointReference$Elements
at public com.sun.xml.ws.developer.MemberSubmissionEndpointReference$Elements com.sun.xml.ws.developer.MemberSubmissionEndpointRefer
ence.referenceProperties
at com.sun.xml.ws.developer.MemberSubmissionEndpointReference
]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:217)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)

解决Qname继续启动,出现这个错误。分析原因还是Jar包问题,从com.sun.xml.ws分析可以看出来启动的时候还是没有使用CXF的包路径.
总结问题1和问题2,我们的目的就是要使用自己的包路径,如果冲突的包不多,将jar包加载到weblogic setDomainEnv里面是最简单的.
比如设置
set PRE_CLASSPATH=C:\temp\webroot\WEB-INF\lib\antlr-xxx.jar;

对于需要修正的类路径可以通过下面的方法进行设置,而不是只用" prefer-web-inf-classes=true" 这个锤子去敲所有的钉子。

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<container-descriptor>
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<!--提示即使weblogic即使有这个包也要优先使用下面路径的内容-->
<prefer-application-resources>
<resource-name>META-INF/services/javax.xml.ws.spi.Provider</resource-name>
</prefer-application-resources>
<prefer-application-packages>
<package-name>org.python.core.*</package-name>
</prefer-application-packages>
</container-descriptor>
</weblogic-web-app>


折腾几个小时,服务启动了,天下太平了。。
新问题

Caused by: java.lang.NoSuchMethodError: org.joda.time.DateTime.<init>(IIIII)V


显然也是jar包找不到了,将org.joda.time.*加入

<prefer-application-packages>
<package-name>org.python.core.*</package-name>
<package-name>org.joda.time.*</package-name>
</prefer-application-packages>

搞定!
页: [1]
查看完整版本: 第二次被CXF+Oracle Weblogic11g 折磨