Java Web Start应用程序无法从快捷方式更新

时间:2022-01-15 10:56:23

I have deployed a Java(FX) desktop app using Java Web Start. The updates work fine but only if I run the downloaded JNLP by hand, they do not work from shortcuts installed to desktop and menu.

我使用Java Web Start部署了一个Java(FX)桌面应用程序。更新工作正常,但只有当我手动运行下载的JNLP时,它们才能从安装到桌面和菜单的快捷方式中运行。

Here is my JNLP:

这是我的JNLP:

<?xml version="1.0" encoding="utf-8"?>
<jnlp codebase="http://192.168.1.85/deploy/" spec="1.0" xmlns:jfx="http://javafx.com" href="Companyapp.jnlp">

    <information>

        <title>Companyapp</title>
        <vendor>Media Citizens</vendor>
        <description>Companyapp Presentation Desktop</description>
        <homepage href="http://192.168.1.85/deploy/"/>

        <offline-allowed/>

        <shortcut online="false" install="true">
            <desktop />
            <menu submenu="Companyapp"/>
        </shortcut>

        <icon kind="shortcut"   href="http://192.168.1.85/deploy/icons/32x32.gif"           width="32"      height="32"     />
        <icon kind="shortcut"   href="http://192.168.1.85/deploy/icons/64x64.gif"           width="64"      height="64"     />
        <icon kind="splash"     href="http://192.168.1.85/deploy/icons/splash_screen.jpg"   width="1024"    height="768"    />
    </information>

    <update check="always" policy="always" />

    <security>
        <all-permissions/>
    </security>

    <resources>
        <jfx:javafx-runtime version="2.2+" href="http://javadl.sun.com/webapps/download/GetFile/javafx-latest/windows-i586/javafx2.jnlp"/>
    </resources>

    <resources>
        <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>

        <jar href="http://192.168.1.85/deploy/Companyapp.jar" main="true"                                   download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/async-http-client-1.7.8.jar"             size="477791"   download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/commons-codec-1.7.jar"                       size="259600"   download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/commons-io-2.4.jar"                          size="185140"   download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/commons-lang3-3.1.jar"                       size="315805"   download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/commons-logging-1.1.jar"                 size="52915"    download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/json-simple-1.1.1.jar"                       size="23737"    download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/slf4j-api-1.7.2.jar"                     size="26083"    download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/sqlite-jdbc-3.7.15-SNAPSHOT.jar"         size="3702257"  download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/ws-commons-util-1.0.2.jar"                   size="34407"    download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/xmlrpc-client-3.1.3.jar"                 size="58573"    download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/xmlrpc-common-3.1.3.jar"                 size="109131"   download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/zt-zip-1.5.jar"                              size="33059"    download="eager"    />
        <jar href="http://192.168.1.85/deploy/libs/javaws.jar"                                  size="893738"   download="eager"    />
    </resources>

    <jfx:javafx-desc  width="0" height="0" main-class="com.mediacitizens.companyapp.presentation.desktop.Main"  name="Company App" />
    <application-desc main-class="com.mediacitizens.companyapp.presentation.desktop.Main" />
</jnlp>

Just in case, here is the part of my program that installs the shortcuts:

以防万一,这是我的程序中安装快捷方式的部分:

// install shortcuts
try
{
    IntegrationService is = null;
    try
    {
        is = (IntegrationService) ServiceManager.lookup("javax.jnlp.IntegrationService");
    }
    catch (UnavailableServiceException use)
    {
        throw new ApplicationError(use.getLocalizedMessage());
    }

    if (!is.hasDesktopShortcut())
    {
        if (!is.requestShortcut(true, true, "Companyapp"))
        {
            throw new ApplicationError("Integration failed.");
        }
    }
    else
    {
        //initialController.dialog("Shortcuts exist", "Go away!", null);
    }
}
catch (ApplicationError e)
{
    initialController.dialog("Failed to integrate a shortcut on your computer.\nCause: " + e.getLocalizedMessage(), "I understand", null);
}

Update 1

I removed <offline-allowed /> and now it updates from a shortcut but I can't start the application offline. So apparently I should be able to? Its giving me this error:

我删除了 ,现在它从快捷方式更新,但我无法启动应用程序脱机。显然我应该能够?它给了我这个错误:

Java Web Start应用程序无法从快捷方式更新

To be fair, I do try to connect to a server on startup, but that is not causing this error: it has a 2 second timeout and looks like that:

公平地说,我确实尝试在启动时连接到服务器,但这不会导致此错误:它有2秒的超时,看起来像这样:

try
{
    isOffline = !(InetAddress.getByName(Config.domain + "." + Config.serverDomain).isReachable(2000));
}
catch (IOException e)
{
    e.printStackTrace();
}

Irregardless, my code is not referenced in the error, so I guess if I don't have <offline-allowed /> I cannot run the app offline at all? Is this true? If yes, this is a massive problem for deployment with JWS, I'll probably just ditch it altogether...

无论如何,我的代码没有在错误中被引用,所以我想如果我没有 我根本无法在线下运行应用程序?这是真的?如果是的话,这对于使用JWS进行部署来说是一个巨大的问题,我可能只是完全放弃了......


Update 2

I think I may be hitting this: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7121086 anyone knows a workaround?

我想我可能会这样:http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7121086任何人都知道一个解决方法?

In the bug it says

在它说的错误

Get rif of every jnlp used as extension. meaning mix all in one. At this condition that works

获取用作扩展名的每个jnlp的rif。意思是混合在一起。在这种情况下工作

So I should mix JavaFX as a jar into my JNLP?

所以我应该将JavaFX作为jar混合到我的JNLP中?

5 个解决方案

#1


2  

I managed to solve the problem without removing <offline-allowed />, here is the JNLP:

我设法在不删除 的情况下解决了问题,这里是JNLP:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="6.0+" codebase="http://192.168.1.85/deploy/" href="Companyapp.jnlp">

    <information>
        <title>Companyapp</title>
        <vendor>Media Citizens</vendor>
        <description>Companyapp Presentation Desktop</description>
        <homepage href="http://192.168.1.85" />

        <shortcut online="true" install="true">
            <desktop />
            <menu submenu="Companyapp" />
        </shortcut>

        <offline-allowed />

        <icon kind="shortcut" href="http://192.168.1.85/deploy/icons/32x32.gif" width="32" height="32" />
        <icon kind="shortcut" href="http://192.168.1.85/deploy/icons/64x64.gif" width="64" height="64" />
        <icon kind="splash" href="http://192.168.1.85/deploy/icons/splash_screen.jpg" width="1024" height="768" />
    </information>

    <update check="always" policy="prompt-update" />

    <security>
        <all-permissions />
    </security>

    <resources>
        <jfx:javafx-runtime version="2.2+" href="http://javadl.sun.com/webapps/download/GetFile/javafx-latest/windows-i586/javafx2.jnlp" />
    </resources>

    <resources>
        <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se" />

        <jar href="http://192.168.1.85/deploy/Companyapp.jar" main="true" />
        <jar href="http://192.168.1.85/deploy/libs/async-http-client-1.7.8.jar" size="477791" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/commons-codec-1.7.jar" size="259600" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/commons-io-2.4.jar" size="185140" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/commons-lang3-3.1.jar" size="315805" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/commons-logging-1.1.jar" size="52915" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/json-simple-1.1.1.jar" size="23737" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/slf4j-api-1.7.2.jar" size="26083" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/sqlite-jdbc-3.7.15-SNAPSHOT.jar" size="3702257" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/ws-commons-util-1.0.2.jar" size="34407" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/xmlrpc-client-3.1.3.jar" size="58573" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/xmlrpc-common-3.1.3.jar" size="109131" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/zt-zip-1.5.jar" size="33059" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/javaws.jar" size="893738" download="eager" />
    </resources>

    <application-desc main-class="com.mediacitizens.companyapp.presentation.desktop.Main" />
</jnlp>

And to make sure the server handles updates correctly, install mod_expires for Apache and put this .htaccess in the folder where the JNLP and JAR are:

要确保服务器正确处理更新,请为Apache安装mod_expires并将此.htaccess放在JNLP和JAR所在的文件夹中:

DirectoryIndex index.html

AddType application/x-java-jnlp-file .jnlp
AddType application/x-java-archive .jar
AddType application/x-java-archive-diff .jardiff

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "modification"
</IfModule>

#2


2  

What was it that made it not work before and what is it about your updated jnlp which allows it to work?

是什么导致它无法正常工作?更新的jnlp是什么让它起作用?

The problem is in the JNLP markup:

问题出在JNLP标记中:

The shortcut container has the attribute: online="false".

快捷方式容器具有以下属性:online =“false”。

This causes the desktop shortcut to be configured, so that it runs javaws with the -offline parameter, so that it runs with the cached jnlp.

这会导致配置桌面快捷方式,以便它使用-offline参数运行javaws,以便它与缓存的jnlp一起运行。

The problem persists even, when you correct the jnlp on the server, because locally the cached jnlp is still being used by the shortcut.

当您更正服务器上的jnlp时,问题仍然存在,因为本地缓存仍然使用缓存的jnlp。

The best solution is to instruct the user to launch the application once more from the browser, since that will cause the javaws to update the shortcut on the client to the correct parameter settings - assuming that you have fixed the jnlp on the server.

最好的解决方案是指示用户再次从浏览器启动应用程序,因为这将导致javaws将客户端上的快捷方式更新为正确的参数设置 - 假设您已在服务器上修复了jnlp。

Actually there's no reason specify this attribute since the default is "true", which would cause the expected behaviour, but the web is afloat with jnlp markup that sets it to false. Also there's virtually no documentation on this attribute, which makes the problem worse.

实际上没有理由指定这个属性,因为默认值是“true”,这会导致预期的行为,但是网络上有jnlp标记,它将其设置为false。此外,几乎没有关于此属性的文档,这使问题变得更糟。

Per

#3


1  

Remove <offline-allowed/> from the JNLP file.

从JNLP文件中删除

If offline-allowed is specified, then the application can be launched offline by the Java Application Cache Viewer, and shortcuts can be created which launch the application offline.

如果指定了offline-allowed,则可以通过Java Application Cache Viewer离线启动应用程序,并可以创建启动应用程序脱机的快​​捷方式。

If an application is launched offline, it will not check for updates and the API call BasicService.isOffline() will return true.

如果应用程序脱机启动,则不会检查更新,API调用BasicService.isOffline()将返回true。

The offline-allowed element also controls how Java Web Start checks for an update to an application. If the element is not specified—i.e., the application is required to be online to run—Java Web Start will always check for an updated version before launching the application. And if an update is found, the new application will be downloaded and launched. Thus, it is guaranteed that the user always runs the latest version of the application. The application, however, must be run online.

offline-allowed元素还控制Java Web Start检查应用程序更新的方式。如果未指定元素 - 即,应用程序必须联机才能运行 - Java Web Start将始终在启动应用程序之前检查更新的版本。如果找到更新,将下载并启动新应用程序。因此,保证用户始终运行最新版本的应用程序。但是,该应用程序必须在线运行。

If offline-allowed is specified, Java Web Start will also check to see if an update is available. However, if the application is already downloaded the check will timeout after a few seconds, in which case the cached application will be launched instead. Given a reasonably fast server connection, the latest version of the application will usually be run, but it is not guaranteed. The application, however, can be run offline.

如果指定了offline-allowed,则Java Web Start还将检查是否有可用的更新。但是,如果已经下载了应用程序,则检查将在几秒钟后超时,在这种情况下,将启动缓存的应用程序。如果服务器连接速度相当快,通常会运行最新版本的应用程序,但不能保证。但是,该应用程序可以脱机运行。

Source: http://docs.oracle.com/javase/1.5.0/docs/guide/javaws/developersguide/syntax.html

资料来源:http://docs.oracle.com/javase/1.5.0/docs/guide/javaws/developersguide/syntax.html

#4


0  

Even though following all of the advice this problem persisted for me (using Java 8 runtime on Windows).

即使按照所有建议,这个问题仍然存在(在Windows上使用Java 8运行时)。

I solved it in my case by ensuring that the webserver that serves the JNLP file adds a Last-Modified header. (I used an embedded Jetty instance and apparently Jetty's ResourceHandler doesn't do this). I also added an expiry date in the past for the jnlp, but I'm not sure if that was necessary.

我通过确保为JNLP文件提供服务的Web服务器添加Last-Modified标头来解决这个问题。 (我使用了一个嵌入式Jetty实例,显然Jetty的ResourceHandler没有这样做)。我还为jnlp添加了过去的失效日期,但我不确定是否有必要。

My old answer which MIGHT help some: I also put the update tag after the security tag as advised here JNLP is not updated even though there is update="always" policy="always"

我的旧答案可能会帮助一些:我也将更新标记放在安全标记之后,如此建议JNLP即使存在update =“always”policy =“always”也不会更新

The problem temporarily seemed to temporarily go away after doing this.

这样做之后,这个问题暂时似乎暂时消失了。

#5


0  

I had this problem just because I didn't let the app opened time enough to complete the update.

我有这个问题只是因为我没有让应用程序打开时间足以完成更新。

If you have this option: update check="background" in your JNLP, wait some time before close the application in order to allow the update (that is running on background) finish.

如果您有这个选项:在JNLP中更新check =“background”,请在关闭应用程序之前等待一段时间,以便完成更新(在后台运行)。

#1


2  

I managed to solve the problem without removing <offline-allowed />, here is the JNLP:

我设法在不删除 的情况下解决了问题,这里是JNLP:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="6.0+" codebase="http://192.168.1.85/deploy/" href="Companyapp.jnlp">

    <information>
        <title>Companyapp</title>
        <vendor>Media Citizens</vendor>
        <description>Companyapp Presentation Desktop</description>
        <homepage href="http://192.168.1.85" />

        <shortcut online="true" install="true">
            <desktop />
            <menu submenu="Companyapp" />
        </shortcut>

        <offline-allowed />

        <icon kind="shortcut" href="http://192.168.1.85/deploy/icons/32x32.gif" width="32" height="32" />
        <icon kind="shortcut" href="http://192.168.1.85/deploy/icons/64x64.gif" width="64" height="64" />
        <icon kind="splash" href="http://192.168.1.85/deploy/icons/splash_screen.jpg" width="1024" height="768" />
    </information>

    <update check="always" policy="prompt-update" />

    <security>
        <all-permissions />
    </security>

    <resources>
        <jfx:javafx-runtime version="2.2+" href="http://javadl.sun.com/webapps/download/GetFile/javafx-latest/windows-i586/javafx2.jnlp" />
    </resources>

    <resources>
        <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se" />

        <jar href="http://192.168.1.85/deploy/Companyapp.jar" main="true" />
        <jar href="http://192.168.1.85/deploy/libs/async-http-client-1.7.8.jar" size="477791" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/commons-codec-1.7.jar" size="259600" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/commons-io-2.4.jar" size="185140" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/commons-lang3-3.1.jar" size="315805" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/commons-logging-1.1.jar" size="52915" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/json-simple-1.1.1.jar" size="23737" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/slf4j-api-1.7.2.jar" size="26083" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/sqlite-jdbc-3.7.15-SNAPSHOT.jar" size="3702257" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/ws-commons-util-1.0.2.jar" size="34407" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/xmlrpc-client-3.1.3.jar" size="58573" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/xmlrpc-common-3.1.3.jar" size="109131" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/zt-zip-1.5.jar" size="33059" download="eager" />
        <jar href="http://192.168.1.85/deploy/libs/javaws.jar" size="893738" download="eager" />
    </resources>

    <application-desc main-class="com.mediacitizens.companyapp.presentation.desktop.Main" />
</jnlp>

And to make sure the server handles updates correctly, install mod_expires for Apache and put this .htaccess in the folder where the JNLP and JAR are:

要确保服务器正确处理更新,请为Apache安装mod_expires并将此.htaccess放在JNLP和JAR所在的文件夹中:

DirectoryIndex index.html

AddType application/x-java-jnlp-file .jnlp
AddType application/x-java-archive .jar
AddType application/x-java-archive-diff .jardiff

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "modification"
</IfModule>

#2


2  

What was it that made it not work before and what is it about your updated jnlp which allows it to work?

是什么导致它无法正常工作?更新的jnlp是什么让它起作用?

The problem is in the JNLP markup:

问题出在JNLP标记中:

The shortcut container has the attribute: online="false".

快捷方式容器具有以下属性:online =“false”。

This causes the desktop shortcut to be configured, so that it runs javaws with the -offline parameter, so that it runs with the cached jnlp.

这会导致配置桌面快捷方式,以便它使用-offline参数运行javaws,以便它与缓存的jnlp一起运行。

The problem persists even, when you correct the jnlp on the server, because locally the cached jnlp is still being used by the shortcut.

当您更正服务器上的jnlp时,问题仍然存在,因为本地缓存仍然使用缓存的jnlp。

The best solution is to instruct the user to launch the application once more from the browser, since that will cause the javaws to update the shortcut on the client to the correct parameter settings - assuming that you have fixed the jnlp on the server.

最好的解决方案是指示用户再次从浏览器启动应用程序,因为这将导致javaws将客户端上的快捷方式更新为正确的参数设置 - 假设您已在服务器上修复了jnlp。

Actually there's no reason specify this attribute since the default is "true", which would cause the expected behaviour, but the web is afloat with jnlp markup that sets it to false. Also there's virtually no documentation on this attribute, which makes the problem worse.

实际上没有理由指定这个属性,因为默认值是“true”,这会导致预期的行为,但是网络上有jnlp标记,它将其设置为false。此外,几乎没有关于此属性的文档,这使问题变得更糟。

Per

#3


1  

Remove <offline-allowed/> from the JNLP file.

从JNLP文件中删除

If offline-allowed is specified, then the application can be launched offline by the Java Application Cache Viewer, and shortcuts can be created which launch the application offline.

如果指定了offline-allowed,则可以通过Java Application Cache Viewer离线启动应用程序,并可以创建启动应用程序脱机的快​​捷方式。

If an application is launched offline, it will not check for updates and the API call BasicService.isOffline() will return true.

如果应用程序脱机启动,则不会检查更新,API调用BasicService.isOffline()将返回true。

The offline-allowed element also controls how Java Web Start checks for an update to an application. If the element is not specified—i.e., the application is required to be online to run—Java Web Start will always check for an updated version before launching the application. And if an update is found, the new application will be downloaded and launched. Thus, it is guaranteed that the user always runs the latest version of the application. The application, however, must be run online.

offline-allowed元素还控制Java Web Start检查应用程序更新的方式。如果未指定元素 - 即,应用程序必须联机才能运行 - Java Web Start将始终在启动应用程序之前检查更新的版本。如果找到更新,将下载并启动新应用程序。因此,保证用户始终运行最新版本的应用程序。但是,该应用程序必须在线运行。

If offline-allowed is specified, Java Web Start will also check to see if an update is available. However, if the application is already downloaded the check will timeout after a few seconds, in which case the cached application will be launched instead. Given a reasonably fast server connection, the latest version of the application will usually be run, but it is not guaranteed. The application, however, can be run offline.

如果指定了offline-allowed,则Java Web Start还将检查是否有可用的更新。但是,如果已经下载了应用程序,则检查将在几秒钟后超时,在这种情况下,将启动缓存的应用程序。如果服务器连接速度相当快,通常会运行最新版本的应用程序,但不能保证。但是,该应用程序可以脱机运行。

Source: http://docs.oracle.com/javase/1.5.0/docs/guide/javaws/developersguide/syntax.html

资料来源:http://docs.oracle.com/javase/1.5.0/docs/guide/javaws/developersguide/syntax.html

#4


0  

Even though following all of the advice this problem persisted for me (using Java 8 runtime on Windows).

即使按照所有建议,这个问题仍然存在(在Windows上使用Java 8运行时)。

I solved it in my case by ensuring that the webserver that serves the JNLP file adds a Last-Modified header. (I used an embedded Jetty instance and apparently Jetty's ResourceHandler doesn't do this). I also added an expiry date in the past for the jnlp, but I'm not sure if that was necessary.

我通过确保为JNLP文件提供服务的Web服务器添加Last-Modified标头来解决这个问题。 (我使用了一个嵌入式Jetty实例,显然Jetty的ResourceHandler没有这样做)。我还为jnlp添加了过去的失效日期,但我不确定是否有必要。

My old answer which MIGHT help some: I also put the update tag after the security tag as advised here JNLP is not updated even though there is update="always" policy="always"

我的旧答案可能会帮助一些:我也将更新标记放在安全标记之后,如此建议JNLP即使存在update =“always”policy =“always”也不会更新

The problem temporarily seemed to temporarily go away after doing this.

这样做之后,这个问题暂时似乎暂时消失了。

#5


0  

I had this problem just because I didn't let the app opened time enough to complete the update.

我有这个问题只是因为我没有让应用程序打开时间足以完成更新。

If you have this option: update check="background" in your JNLP, wait some time before close the application in order to allow the update (that is running on background) finish.

如果您有这个选项:在JNLP中更新check =“background”,请在关闭应用程序之前等待一段时间,以便完成更新(在后台运行)。