当WEB-INF/lib和CLASSPATH中包含同一Jar时,类强制转换异常 [英] Class Cast Exception When Same Jar is Included in WEB-INF/lib and CLASSPATH
问题描述
我将一个.jar文件添加到JBoss 5启动文件的CLASSPATH中(run.bat/run.sh).这是从基于servlet的应用程序引用的依赖项jar.如果使用此设置,则servlet可以正常加载并按预期工作.但是,我注意到,如果我在Servlet的WEB-INF/lib目录中具有相同的jar,则会得到如下的类强制转换异常:
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?
谢谢.
推荐答案
您要提及的jar文件已经可以在JBoss
中使用.您将其放置在WEB-INF/lib
中的位置; JBoss已经从JBoss可用的jar
中加载了该类,并且与web-inf
文件夹中的类冲突.即使不同的类加载器加载的类相同,也将被视为不同的类.
输入run.bat
时,只会加载一个jar
文件. JBoss加载了此文件,并且没有冲突的jar.
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.
这篇关于当WEB-INF/lib和CLASSPATH中包含同一Jar时,类强制转换异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!