java - 使用 jnlp 文件在小程序中无法进行延迟 jar 加载的原因可能是什么?

标签 java jar applet jnlp next-generation-plugin

我在 http 页面中嵌入了小程序。 Applet 已签名(与我使用的所有 jar 一样),并且它使用新的 java 插件,该插件允许使用 jnlp 将 applet 嵌入网页中。 我想延迟加载我的小程序所需的 jar 文件之一,但我无法使其工作。

这是我的 jnlp 文件:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" href="/GUI.jnlp">
    <information>
        <title>My Applet</title>
        <vendor>My Company</vendor>
    </information>
    <resources>
        <j2se href="http://java.sun.com/products/autodl/j2se" version="1.6+"/>   
        <jar href="/mainGUI.jar" main="true"/>
        <jar href="/external_1.jar"/>
        <jar href="/external_2.jar"/>
        <jar href="/external_3.jar" download="lazy"/>
    </resources>
    <applet-desc
         name="My Applet"
         main-class="com.xformation.GUIAppletMain"
         width="800"
         height="600">
    </applet-desc>
</jnlp>

和 html 文件:

<APPLET width="100%" height="100%" name="My App" code="CompatibilityApplet" archive="mainGUI.jar">
    <param name="jnlp_href" value="GUI.jnlp">
    <script type="text/javascript">
        <!--
            document.write('<param name="server_address" value="' + window.location.href + '">');
        //-->
    </script>
</APPLET>

另外,在 mainGUI.jar 文件中,我有 ant 生成的正确的 INDEX 文件:

<target name="-do-jar-with-manifest" depends="compile">
    <jar destfile="${dist.jar}"  basedir="${build.classes.dir}" index="true">
        <indexjars>
            <fileset dir="libs">
                <include name="**/external_1.jar"/>
                <include name="**/external_2.jar"/>
                <include name="**/external_3.jar"/>
            </fileset>
        </indexjars>
    </jar>
</target>

据我所知,mainGUI.jar 文件甚至没有被网络浏览器加载为第一个文件(实际上是最后一个),因此 INDEX 文件无法正确使用来检查应该下载哪些文件。

知道我做错了什么吗?

//编辑

java 控制台的输出:

给你:

security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.
security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws
security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws
security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy
security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy
security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.definition value null
security: property package.definition new value com.sun.javaws
security: property package.definition value com.sun.javaws
security: property package.definition new value com.sun.javaws,com.sun.deploy
security: property package.definition value com.sun.javaws,com.sun.deploy
security: property package.definition new value com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss
security: property package.definition value com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.definition new value com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss
network: Created version ID: 1.6.0.26
network: Created version ID: 1.6
network: Created version ID: 1.6.0.26
network: Created version ID: 1.6
network: Created version ID: 1.6.0.26
network: Created version ID: 1.6
network: Created version ID: 1.6.0.26
network: Created version ID: 1.6
network: Connecting http://192.168.22.124:6500/mainGUI.jnlp with proxy=DIRECT
network: Connecting http://192.168.22.124:6500/ with proxy=DIRECT
network: ResponseCode for http://192.168.22.124:6500/mainGUI.jnlp : 200
network: Encoding for http://192.168.22.124:6500/mainGUI.jnlp : null
network: Sever response: (length: 703, lastModified: Thu Oct 27 13:12:43 CEST 2011, downloadVersion: null, mimeType: text/plain)
network: Downloading resource: http://192.168.22.124:6500/mainGUI.jnlp
    Content-Length: 703
    Content-Encoding: null
network: Wrote URL http://192.168.22.124:6500/mainGUI.jnlp to File C:\Users\pkukielka\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\25\5cfa5999-21379497-temp
network: Disconnect connection to http://192.168.22.124:6500/mainGUI.jnlp
temp: new XMLParser with source:
temp: <?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" href="/mainGUI.jnlp">
    <information>
        <title>xxx</title>
        <vendor>xxx</vendor>
    </information>
    <resources>
        <j2se href="http://java.sun.com/products/autodl/j2se" version="1.6+"/>   
        <jar href="/swingx-core-1.6.2.jar"/>
        <jar href="/jfreechart-1.0.13.jar"/>
        <jar href="/axis.jar" download="lazy"/>
        <jar href="/mainGUI.jar" download="eager" main="true"/>
    </resources>
    <applet-desc
         name="LM-X Manager Applet"
         main-class="com.company.mainGUIApplet"
         width="800"
         height="600">
    </applet-desc>
</jnlp>

temp: 

returning ROOT as follows:

<jnlp spec="1.0+" href="/mainGUI.jnlp">
  <information>
    <title>xxx</title>
    <vendor>xxx</vendor>
  </information>
  <resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.6+"/>
    <jar href="/swingx-core-1.6.2.jar"/>
    <jar href="/jfreechart-1.0.13.jar"/>
    <jar href="/axis.jar" download="lazy"/>
    <jar href="/mainGUI.jar" download="eager" main="true"/>
  </resources>
  <applet-desc name="xxx" main-class="com.company.mainGUIApplet" width="800" height="600"/>
</jnlp>jnlp
temp: returning LaunchDesc from XMLFormat.parse():

<jnlp spec="1.0+" codebase="http://192.168.22.124:6500/" href="http://192.168.22.124:6500/mainGUI.jnlp">
  <information>
    <title>xxx</title>
    <vendor>xxx</vendor>
    <homepage href="null"/>
  </information>
  <update check="timeout" policy="always"/>
  <resources>
    <java href="http://java.sun.com/products/autodl/j2se" version="1.6+"/>
    <jar href="http://192.168.22.124:6500/swingx-core-1.6.2.jar" download="eager" main="false"/>
    <jar href="http://192.168.22.124:6500/jfreechart-1.0.13.jar" download="eager" main="false"/>
    <jar href="http://192.168.22.124:6500/axis.jar" download="lazy" main="false"/>
    <jar href="http://192.168.22.124:6500/mainGUI.jar" download="eager" main="true"/>
  </resources>
  <applet-desc name="xxx" main-class="com.company.mainGUIApplet" documentbase="http://192.168.22.124:6500/" width="800" height="600"/>
</jnlp>
basic: Plugin2ClassLoader.addURL2 called for http://192.168.22.124:6500/mainGUI.jar
basic: Plugin2ClassLoader.addURL2 called for http://192.168.22.124:6500/swingx-core-1.6.2.jar
basic: Plugin2ClassLoader.addURL2 called for http://192.168.22.124:6500/jfreechart-1.0.13.jar
basic: Plugin2ClassLoader.addURL2 called for http://192.168.22.124:6500/axis.jar
basic: Plugin2ClassLoader.drainPendingURLs addURL called for http://192.168.22.124:6500/mainGUI.jar
basic: Plugin2ClassLoader.drainPendingURLs addURL called for http://192.168.22.124:6500/swingx-core-1.6.2.jar
basic: Plugin2ClassLoader.drainPendingURLs addURL called for http://192.168.22.124:6500/jfreechart-1.0.13.jar
basic: Plugin2ClassLoader.drainPendingURLs addURL called for http://192.168.22.124:6500/axis.jar
network: No Custom Progress jar
network: Connecting http://192.168.22.124:6500/axis.jar with proxy=DIRECT
network: Downloading resource: http://192.168.22.124:6500/axis.jar
    Content-Length: 1 972 163
    Content-Encoding: null
security: Blacklist revocation check is enabled
network: LaunchDownload: concurrent downloads from LD: 4
network: Total size to download: -1
network: Connecting http://192.168.22.124:6500/jfreechart-1.0.13.jar with proxy=DIRECT
network: Connecting http://192.168.22.124:6500/swingx-core-1.6.2.jar with proxy=DIRECT
network: Connecting http://192.168.22.124:6500/mainGUI.jar with proxy=DIRECT
network: Connecting http://192.168.22.124:6500/ with proxy=DIRECT
network: Connecting http://192.168.22.124:6500/ with proxy=DIRECT
network: Downloading resource: http://192.168.22.124:6500/jfreechart-1.0.13.jar
    Content-Length: 1 479 993
    Content-Encoding: null
network: Validating http://192.168.22.124:6500/jfreechart-1.0.13.jar , version null...
network: Downloaded http://192.168.22.124:6500/jfreechart-1.0.13.jar: null
network: Download Progress: jarsDone: 1
network: Downloading resource: http://192.168.22.124:6500/mainGUI.jar
    Content-Length: 881 140
    Content-Encoding: null
network: Validating http://192.168.22.124:6500/mainGUI.jar , version null...
network: Downloaded http://192.168.22.124:6500/mainGUI.jar: null
network: Download Progress: jarsDone: 2
network: Downloading resource: http://192.168.22.124:6500/swingx-core-1.6.2.jar
    Content-Length: 1 569 320
    Content-Encoding: null
network: Validating http://192.168.22.124:6500/swingx-core-1.6.2.jar , version null...
network: Downloaded http://192.168.22.124:6500/swingx-core-1.6.2.jar: null
network: Download Progress: jarsDone: 3
network: Created version ID: 1.6+
network: Created version ID: 1.6.0.26
network: Created version ID: 1.6.0.26
network: Created version ID: 1.6
basic: LaunchDesc location: http://192.168.22.124:6500/mainGUI.jnlp
network: Created version ID: 1.0+
network: Created version ID: 6.0.18
basic: passing security checks; secureArgs:true, allSigned:false
basic: continuing launch in this VM
(...) <- here 500 lines with loaded classses listed, nothing form axis library

一项更新: 由于我使用自己的网络服务器运行这个示例,因此我使用调试器运行它,并跳过应该延迟加载的服务库(我只是返回空文件)。 然后我得到了这个错误:

java.io.FileNotFoundException: http://192.168.22.124:6500/axis.jar?version-id=1.0
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getJarFileWithoutCache(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getJarFileWithoutCache(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCachedJarFile(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCachedJarFile(Unknown Source)
at com.sun.javaws.LaunchDownload.downloadEagerorAll(Unknown Source)
at sun.plugin2.applet.JNLP2Manager.downloadResources(Unknown Source)
at sun.plugin2.applet.JNLP2Manager.prepareLaunchFile(Unknown Source)
at sun.plugin2.applet.JNLP2Manager.loadJarFiles(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

对我来说非常可疑的一行是:

at com.sun.javaws.LaunchDownload.downloadEagerorAll(Unknown Source)

那又怎么样,看起来所有惰性下载都被忽略了?问题是为什么?

最佳答案

好的,我找到了答案。

看完之后 http://javasourcecode.org/html/open-source/jdk/jdk-6u23/com/sun/javaws/LaunchDownload.java.html我注意到这一行:

  868   // We will eagerly download all lazy resources that have already been cached too.
  869   // Otherwise, we might not detect that an update have happend

嗯,我确信我的缓存已被清除,因为在我的开发人员机器上我已完全禁用它。只是出于好奇,我再次启用它,并尝试运行我的小程序。

现在可以使用了。

所以:请注意,延迟加载在禁用缓存的情况下不起作用。

关于java - 使用 jnlp 文件在小程序中无法进行延迟 jar 加载的原因可能是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7913045/

相关文章:

java - Mac OS High Sierra 上的 mailR send.mail Java 错误

intellij-idea - 执行jar时intellij中的"no main manifest attribute"错误

java - 在 JRuby 中调用自定义 Java 类

java - 如何为特定包maven创建jar

java - Java 小程序和网页上的文本输入控件之间的桥梁

java - 无法在 Netbeans IDE 打包的浏览器中运行简单的 JavaFX

java - 使用 java 小程序的连续动画

java - 如何从文本文件中选取一行并将其转换为数组对象?

java - 是否可以在 JTextField 上为文本加下划线?如果可以,怎么做?

java - AES 加密 Java 到 C#