![](/img/trans.png)
[英]java.lang.classcastexception com.ibm.ws.rsadapter.jdbc.wsjdbcconnection incompatible with oracle.jdbc.oracleConnection
[英]java.lang.ClassCastException: com.ibm.ws.classloader.Handler$ClassLoaderURLConnection incompatible with java.net.JarURLConnection
如何列出包含wsjar文件的目录的内容?
以下代码不适用于WebSphere,但适用于JBoss:
Enumeration<URL> en = getClass( ).getClassLoader( ).getResources( "com/myjars" );
while( en.hasMoreElements( ) ) {
URL url = en.nextElement( );
if( url.toString( ).startsWith( "jar:file:" ) || url.toString( ).startsWith( "wsjar:file:" ) ) {
JarFile jarFile = ( (JarURLConnection)url.openConnection( ) ).getJarFile( );
Enumeration<JarEntry> eje = jarFile.entries( );
while( eje.hasMoreElements( ) ) {
JarEntry jarEntry = eje.nextElement( );
System.out.println( jarEntry.getName( ) );
}
}
}
在WebSphere上,我得到了:
java.lang.ClassCastException:com.ibm.ws.classloader.Handler $ ClassLoaderURLConnection与java.net.JarURLConnection不兼容
您可能会尝试通过从URL剥离jar:file:
并使用ZipFile
类型来打开jar:file:
,因为您并不是真的对jar作为jar感兴趣,而是对jar中的文件(只是一个zip文件)感兴趣。
因此, "jar:file:///foo/bar/baz.jar"
变为"/foo/bar/baz.jar"
,您将其传递给ZipFile(String)
构造函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.