Java Web Start app fails to update from a shortcut

2019-03-31 19:13发布

问题:

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.

Here is my 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:

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:

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...


Update 2

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

In the bug it says

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

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

回答1:

I managed to solve the problem without removing <offline-allowed />, here is the 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:

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:

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

The problem is in the JNLP markup:

The shortcut container has the attribute: 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.

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

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.

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.

Per



回答3:

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

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.

If an application is launched offline, it will not check for updates and the API call BasicService.isOffline() will return 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.

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.

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



回答4:

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

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.

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"

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



回答5:

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.