问题
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