带有版本更新的Java WebStart

时间:2011-06-01 06:01:38

标签: java java-web-start

我正在使用Java WebStart和我正在处理的这个简单的应用程序,我也做了它,以便它能够检查最新版本的jar文件的更新。虽然在运行它时,我收到一条错误消息,指出服务器缺少版本响应。

下面是我的jnlp文件代码:

<?xml version="1.0" encoding="utf-8"?> 
<jnlp spec="1.0+" codebase="http://localhost:8081/WebStartLauncher/app" href="Agecalc.jnlp">
    <information>
    <title>Jnlp Testing</title>
    <vendor>Peter Ivan & co</vendor>
    <homepage href="http://localhost:8081/WebStartLauncher" />
    <description>Testing Testing</description>
    <icon href="app/index.jpeg" kind="default"/>
    <icon kind="shortcut" href="app/index.jpeg" width="32" height="32"/>
    <offline-allowed/>
</information>
<security>
    <all-permissions/>
</security>
<resources>
    <j2se version="1.6+" />
    <jar href="AgeCalc__V1.0.jar" version="1.0"/>
    <jar href="AgeCalc__V1.1.jar" version="1.1"/>
    <property name="jnlp.versionEnabled" value="true"/>
</resources>
<application-desc main-class="com.webstart.AgeCalculator" />
</jnlp>

用于version.xml:

<jnlp-versions>
  <resource>
     <pattern>
       <name>AgeCalc__V1.0.jar</name>
        <version-id>1.0</version-id>
     </pattern>
     <file>AgeCalc__V1.0.jar</file>
  </resource>
</jnlp-versions>

表示web.xml:

<?xml version="1.0" encoding="UTF-8"?>
  <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>WebStartLauncher</display-name>
<welcome-file-list>
    <welcome-file>webstart.jsp</welcome-file>
</welcome-file-list>
<servlet>
    <servlet-name>JnlpDownloadServlet</servlet-name>
    <servlet-class>jnlp.sample.servlet.JnlpDownloadServlet</servlet-class>
 </servlet>
 <servlet-mapping>
    <servlet-name>JnlpDownloadServlet</servlet-name>
    <url-pattern>/WebContent/WEB-INF/lib</url-pattern>
 </servlet-mapping>
</web-app>

这些是我得到的错误日志:

com.sun.deploy.net.FailedDownloadException: Unable to load resource: (http://localhost:8081/WebStartLauncher/app/AgeCalc__V1.0.jar, 1.0)
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)
at com.sun.javaws.LaunchDownload.downloadJarFiles(Unknown Source)
at com.sun.javaws.LaunchDownload.downloadEagerorAll(Unknown Source)
at com.sun.javaws.Launcher.downloadResources(Unknown Source)
at com.sun.javaws.Launcher.prepareLaunchFile(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


java.io.IOException: missing version response from server
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)
at com.sun.javaws.LaunchDownload.downloadJarFiles(Unknown Source)
at com.sun.javaws.LaunchDownload.downloadEagerorAll(Unknown Source)
at com.sun.javaws.Launcher.downloadResources(Unknown Source)
at com.sun.javaws.Launcher.prepareLaunchFile(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

请告知如何继续。非常感谢!

2 个答案:

答案 0 :(得分:4)

基于http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/downloadservletguide.html#requests我认为,您正在为基于版本的下载混合两种可能的策略。对于任何jar资源,您可以使用任一文件名约定,您不需要version.xml条目,并且您的jnlp条目将读取

<jar href="AgeCalc.jar" version="1.0"/>

并且servlet将自动使用AgeCalc__V1.0.jar。

另一种可能的方法是写

<resource>
   <pattern>
     <name>AgeCalc.jar</name>
     <version-id>1.0</version-id>
   </pattern>
   <file>AgeCalc__V1.0.jar</file>
</resource>

在您的version.xml中与上面更改的jnlp结合使用。但由于您使用的是文件名约定,我建议不要使用version.xml。

当jnlp中的href包含__V时,可能是DownloadServlet有问题。

但从Java 7开始,您甚至不再需要下载servlet了。现在,客户端可以发挥魔力。您所要做的就是为您的jnlp添加一个值为true的系统属性jnlp.versionEnabled。只要服务器上的文件是* __ V $ {version} .jar形式,everything will work correctly

但您可以使用my gradle plugin,它会自动创建一个正确的webstart目录,随时可以打包以进行部署。

答案 1 :(得分:0)

您应该检查文件名。

AgeCalc__V1.0.jar与AgeCalc_V1.0.jar不同。

重命名jar文件时,请确保在版本号之前包含两个下划线(__)。

<resources>
    <j2se version="1.6+" />
    <jar href="AgeCalc.jar" version="1.0"/>
    <jar href="AgeCalc.jar" version="1.1"/>
    <property name="jnlp.versionEnabled" value="true"/>
</resources>

文件名 AgeCalc__V1.0.jar和 AgeCalc__V1.1.jar