我尝试使用以下代码动态加载 jar 资源。
DownloadService ds;
try {
ds = (DownloadService)ServiceManager.lookup("javax.jnlp.DownloadService");
// determine if a particular resource is cached
URL url =
new URL("http://localhost:11090/MultiToolkitDemo/download/ubikey-1.0.2.5.jar");
boolean cached = ds.isResourceCached(url, "1.0");
// remove the resource from the cache
if (cached) {
ds.removeResource(url, "1.0");
}
// reload the resource into the cache
DownloadServiceListener dsl = ds.getDefaultProgressWindow();
ds.loadResource(url, "1.0", dsl);
} catch (Exception e) {
e.printStackTrace();
}
但我得到如下错误。
cache: Create from verifier: JarSigningData{hasOnlySignedEntries=true, hasSingleCodeSource=true, hasMissingSignedEntries=false}
network: Cache: Enable a new CacheEntry: http://localhost:11090/MultiToolkitDemo/download/ubikey-1.0.2.5.jar
network: CleanupThread used 1 us
network: Downloaded http://localhost:11090/MultiToolkitDemo/download/ubikey-1.0.2.5.jar: C:\Users\Administrator\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\63\774e407f-457c5f64-1.0-
cache: Adding MemoryCache entry: http://localhost:11090/MultiToolkitDemo/download/ubikey-1.0.2.5.jar
network: Download Progress: jarsDone: 1
2013-08-30 14:19:53,959 4881 [AWT-EventQueue-2] INFO com.ktnet.pki.multibrowser.dialog.SelectCertificateDlg$10 - MOBILE_PHONE param BOKJIRO;KTNET;null;null;null
security: blacklist: hasBeenModifiedSince 1377837583053 (we have 1377739208656)
network: cache found [URL: http://localhost:11090/MultiToolkitDemo/download/ubikey-1.0.2.5.jar, 버전: null] prevalidated=false/0
cache: MemoryCache replacing http://localhost:11090/MultiToolkitDemo/download/ubikey-1.0.2.5.jar (refcnt=2). Was: URL: http://localhost:11090/MultiToolkitDemo/download/ubikey-1.0.2.5.jar | C:\Users\Administrator\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\63\774e407f-457c5f64-1.0-.idx Now: URL: http://localhost:11090/MultiToolkitDemo/download/ubikey-1.0.2.5.jar | C:\Users\Administrator\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\63\774e407f-13638c52.idx
cache: Reading Signers from 4389 http://localhost:11090/MultiToolkitDemo/download/ubikey-1.0.2.5.jar | C:\Users\Administrator\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\63\774e407f-13638c52.idx
cache: Done readSigners(http://localhost:11090/MultiToolkitDemo/download/ubikey-1.0.2.5.jar)
cache: Read manifest for http://localhost:11090/MultiToolkitDemo/download/ubikey-1.0.2.5.jar: read=72 full=5090
Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
at sun.plugin2.applet.JNLP2ClassLoader.getAppInfo(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.isTrustedByTrustDecider(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.getTrustedCodeSources(Unknown Source)
at com.sun.deploy.security.CPCallbackHandler$ParentCallback.strategy(Unknown Source)
at com.sun.deploy.security.CPCallbackHandler$ParentCallback.openClassPathElement(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath$JarLoader.getJarFile(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath$JarLoader.access$1000(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath$JarLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.deploy.security.DeployURLClassPath$JarLoader.ensureOpen(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath$JarLoader.<init>(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.deploy.security.DeployURLClassPath.getLoader(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath.getLoader(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath.getResource(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
at sun.plugin2.applet.JNLP2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.ktnet.pki.multibrowser.certificate.infovine.InfovineController.init(InfovineController.java:19)
我认为 AppInfo 丢失了。有没有办法动态插入 AppInfo。
顺便说一下,像下面这样在 jnlp 中指定 jar 可以正常工作。
<resources>
<j2se version="1.6+" java-vm-args="-Dfile.encoding=UTF-8" />
<jar href="ubikey-1.0.2.5.jar" />
</resources>