Class Cast Exception When Same Jar is Included in WEB-INF/lib and CLASSPATH

£可爱£侵袭症+ 提交于 2019-12-11 04:23:28

问题


I have a .jar file added to the CLASSPATH of the JBoss 5 startup (run.bat/run.sh) file. This is a dependency jar which is referred to from the servlet based application. If I use this setup, the servlet loads fine and works as expected. However, I noted that if I have the same jar in the servlet's WEB-INF/lib directory, I get a class cast exception as follows:

ERROR [STDERR] ERROR: com.idoox.wasp.ProtocolRepositoryImpl - Exception in protocolHandler soap, protocolHandler com.server.saaj.soap.SOAP11ProtocolHandler, class space root.wasp-impl.SOAP : 
ERROR [STDERR] EXCEPTION: 
ERROR [STDERR] com.systinet.saaj.soap.SOAP11ProtocolHandler cannot be cast to org.idoox.wasp.ProtocolHandler 
ERROR [STDERR] java.lang.ClassCastException: com.server.saaj.soap.SOAP11ProtocolHandler cannot be cast to org.idoox.wasp.ProtocolHandler 

This is not an issue since I won't have the jar in both places, but I'm just wondering why it is happening this way. Is this a class loading issue?

Thank You.


回答1:


The jar file you are mentioning would be already available with JBoss. Whe you place it in the WEB-INF/lib; JBoss has already loaded the class from the jar available with JBoss and there is conflict with the class in the web-inf folder. Classes loaded by different classloaders are treated as different even if the classes are same.
When you give in run.bat there is only one jar file loaded. JBoss loads this and there is no conflicting jars.



来源:https://stackoverflow.com/questions/12576035/class-cast-exception-when-same-jar-is-included-in-web-inf-lib-and-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!