[英]Class Cast Exception When Same Jar is Included in WEB-INF/lib and CLASSPATH
I have a .jar file added to the CLASSPATH of the JBoss 5 startup (run.bat/run.sh) file. 我有一个.jar文件添加到JBoss 5启动(运行.bat / run.sh)文件的CLASSPATH中。 This is a dependency jar which is referred to from the servlet based application.
这是从基于servlet的应用程序引用的依赖项jar。 If I use this setup, the servlet loads fine and works as expected.
如果使用此设置,则servlet可以正常加载并按预期工作。 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:
但是,我注意到,如果我在Servlet的WEB-INF / lib目录中具有相同的jar,则会得到如下的类强制转换异常:
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. 谢谢。
The jar file you are mentioning would be already available with JBoss
. 您提到的jar文件已经可以在
JBoss
。 Whe you place it in the WEB-INF/lib
; 您将其放在
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. JBoss已经从JBoss可用的
jar
加载了该类,并且与web-inf
文件夹中的类存在冲突。 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. 输入
run.bat
,仅加载一个jar
文件。 JBoss loads this and there is no conflicting jars. JBoss加载了这个,并且没有冲突的jar。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.