首先申明,我用的JDIC版本是2006-1102。
在我的之前的一篇介绍swing内嵌IE浏览器的文章(http://llyer110.iteye.com/blog/759752),介绍了一个第三方库——jdic,我们这里将介绍在运用该库时容易遇到的一个问题解决方案
之前你要肯定你的应用程序是采用的java webstart,至于其他方式下有无该问题,恕小弟不才,没有经历过!
一、问题来源
在服务器端部署好一个java webstart的应用程序后,客户端访问调用了jdic包的地方时,产生如下错误:
Unexpected ClassLoader for webstart, only com.sun.jnlp.JNLPClassLoader is supported.
这是怎么回事呢?没有找到jdic的包,我已经放到jre/lib/ext目录下了呀? 我告诉你,你这就错了,很明显从错误来看,并非是没有找到相关包的错误信息。经过分析知道,在客户端环境下,jdic的类加载器是ExtClassLoader,而在javawebstart方式下,jdic只支持JnlpClassLoader,从如下代码中可以看出来
private String caculateNativeLibPathBySunJWS()
throws IOException, JdicInitException
{
String str1 = null;
ClassLoader localClassLoader = super.getClass().getClassLoader();
if (localClassLoader instanceof JNLPClassLoader)
{
JNLPClassLoader localJNLPClassLoader = (JNLPClassLoader)localClassLoader;
try {
Method findLibraryMethod = localJNLPClassLoader.getClass().getDeclaredMethod("findLibrary", new Class[] { String.class });
findLibraryMethod.setAccessible(true);
Object[] paramters = { new String("jdic") };
String str2 = (String)findLibraryMethod.invoke(localJNLPClassLoader, paramters);
str1 = new File(str2).getParentFile().getCanonicalPath();
WebBrowserUtil.trace("running path " + this.nativeLibPath);
this.isShareNativeInitialized = true;
} catch (Exception e) {
e.printStackTrace();
}
}
else
{
throw new JdicInitException("Unexpected ClassLoader for webstart, only com.sun.jnlp.JNLPClassLoader is supported.");
}
return str1;
}
再看以下源代码(initShareNative()中):
String str1 = System.getProperty("javawebstart.version");
if (str1 != null)
{
WebBrowserUtil.trace("Loaded by JavaWebStart,version is " + str1);
this.nativeLibPath = caculateNativeLibPathBySunJWS();
return;
}
所以不难得出为什么在开发环境下,能够正常运行了
二、解决方案
通过以上原因的分析,我将jdic.jar放在服务端,并在jnlp文件中的<resources>标签下增加代码:
<jar href="jdic.jar" download="lazy"/>
让他从这里载入,问题解决了!
哦!别忘了为新添加的jar包签名哟!