2011-06-01 61 views
2

我正在使用Java WebStart以及我正在使用的這個簡單應用程序,並且還使其能夠檢查最新版本的jar文件的更新。儘管在運行它時,我收到一條錯誤消息,指出服務器缺少版本響應。具有版本更新的Java WebStart

下面

是我的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) 

請告知如何繼續。非常感謝!

回答

3

基於http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/downloadservletguide.html#requests我認爲,你正在混合兩種可能的策略來進行基於版本的下載。對於任何廣口瓶的資源,你可以使用文件名約定,在那裏你不需要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。

也許DownloadServlet在jnlp中的href包含__V時有問題。

但是從Java 7開始,你甚至不需要下載servlet。現在客戶可以做到這一點。所有你需要做的就是添加一個系統屬性jnlp.versionEnabled值爲true到你的jnlp。只要服務器上的文件爲* __ V $ {version} .jar格式,即everything will work correctly

但是你可以使用my gradle plugin,它會自動創建一個正確的webstart目錄,準備打包部署。

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