Class Cast Exception When Same Jar is Included in

2019-07-25 17:39发布

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条回答
成全新的幸福
2楼-- · 2019-07-25 17:53

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.

查看更多
登录 后发表回答