如何从JNLP资源标记中以* .jar结尾的资源加载JAR?

时间:2012-01-03 13:52:23

标签: jnlp java-web-start

我想用Java Web Start运行JAR文件。不幸的是,我必须动态加载JAR文件(它存储在Moodle中)。因此,指向JAR文件的链接不会以“.jar”结尾。它实际上是对PHP脚本的调用,它动态加载JAR文件。如果我用浏览器打开链接,则会下载JAR文件。无论如何,Java Web Start无法像这样下载它。我得到以下异常:

  

com.sun.deploy.net.FailedDownloadException:Ressource konnte nicht geladen werden:http://localhost/moodle22/pluginfile.php/39/mod_assignment/my_file       at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)       at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)       at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)       at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)       at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)       at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)       在com.sun.javaws.LaunchDownload $ DownloadTask.call(未知来源)       at java.util.concurrent.FutureTask $ Sync.innerRun(Unknown Source)       at java.util.concurrent.FutureTask.run(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)       在java.lang.Thread.run(未知来源)

封装的例外:

  

java.io.IOException:无效的jar文件       在com.sun.deploy.net.HttpDownloadHelper.download(未知来源)       at com.sun.deploy.cache.Cache.downloadResourceToTempFile(Unknown Source)       at com.sun.deploy.cache.Cache.downloadResourceToCache(Unknown Source)       at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)       at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)       at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)       at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)       at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)       at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)       在com.sun.javaws.LaunchDownload $ DownloadTask.call(未知来源)       at java.util.concurrent.FutureTask $ Sync.innerRun(Unknown Source)       at java.util.concurrent.FutureTask.run(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)       在java.lang.Thread.run(未知来源)

我的JNLP档案:

<?xml version="1.0" encoding="utf-8"?>
<jnlp codebase="http://localhost">
  <information>
    <title>Test</title>
    <vendor>Me</vendor>
    <homepage href="http://www.google.com"/>
    <description>Test</description>
    <offline-allowed/>
  </information>
  <security>
    <all-permissions/>
  </security>
  <resources>
    <java version="1.5+"/>
    <jar href="moodle22/pluginfile.php/39/mod_assignment/my_file"/>
  </resources>
  <application-desc>
    <argument>--argument</argument>
  </application-desc>
</jnlp>

如果我用这样的直接链接引用JAR,一切都按预期工作:

<resources>
    <java version="1.5+"/>
    <jar href="moodle22/mod/assignment/type/something/tmp/test.jar"/>
</resources>

1 个答案:

答案 0 :(得分:1)

谢谢@Amadan!

Java Web Start实际上可以从不以“.jar”结尾的资源加载JAR。只需要设置适当的内容类型:

Content-type: application/java-archive

然后它完美地运作: - )