简体   繁体   中英

JavaFX deployment through Java Web Start - Loading Progress Bar

My app is deployed by JavaWS but after the user clicks on the JNLP there is a long pause where nothing seemingly happens, then the app pops up on the screen. JavaWS is downloading all the JARs in the background but there is no progress indication, which is very poor. So I set about building a custom one:

public class LoadingProgress implements DownloadServiceListener
{
    Stage       stage;
    TextArea    log = new TextArea();

    public LoadingProgress()
    {
        stage = new Stage(StageStyle.UNDECORATED);
        stage.setScene(new Scene(PaneBuilder.create().children(log).prefHeight(300).prefWidth(300).build()));
        stage.show();
    }

    @Override
    public void downloadFailed(URL url, String version)
    {
        log.appendText(String.format("failed url=%s version=%s\n", url, version));
    }

    @Override
    public void progress(URL url, String version, long readSoFar, long total, int overallPercent)
    {
        log.appendText(String.format("progress url=%s version=%s readSoFar=%d total=%d overallPercent=%d\n", url, version, readSoFar, total, overallPercent));
    }

    @Override
    public void upgradingArchive(URL url, String version, int patchPercent, int overallPercent)
    {
        log.appendText(String.format("validating url=%s version=%s patchPercent=%d overallPercent=%d\n", url, version, patchPercent, overallPercent));
    }

    @Override
    public void validating(URL url, String version, long entry, long total, int overallPercent)
    {
        log.appendText(String.format("validating url=%s version=%s entry=%d total=%d overallPercent=%d\n", url, version, entry, total, overallPercent));
    }

}

And here is my JNLP below. You will notice I tried using the custom loader class in three different ways none of which work on their own or put together :

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="6.0+" codebase="${url}" xmlns:jfx="http://javafx.com" href="Companyapp.jnlp">

    <information>
        ... info ...
    </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 assets ...
    </resources>

    <jfx:javafx-desc main-class="com.mediacitizens.companyapp.presentation.desktop.Main" name="Companyapp" progress-class="com.mediacitizens.companyapp.presentation.desktop.LoadingProgress" /> <!--  width="0" height="0" //-->
    <application-desc main-class="com.mediacitizens.companyapp.presentation.desktop.Main" progress-class="com.mediacitizens.companyapp.presentation.desktop.LoadingProgress" />
    <component-desc progress-class="com.mediacitizens.companyapp.presentation.desktop.LoadingProgress" />
</jnlp>

So none of this makes any difference. Nothing interesting is printed to console either, even with full logging + tracing.

What is going on?

I can't tell you exactly what is going wrong with your setup, but you don't need to implement your own DownloadService to handle this. Instead, I recommend using a JavaFX preloader following Oracle's official Java deployment guide for Preloaders . The guide provides performance tips for efficient startup of applications, including stuff such as separating the preloader into it's own jar file, not blocking the JavaFX application thread, enabling background update checks, marking some jars lazy loaded, disabling auto proxy configuration etc.

By using the tools in the official Oracle JavaFX deployment guide, you should not need to hand edit a jnlp file as the tools should generate one for you to load your application efficiently.

Following the Trouble Shooting Guide for Java Desktop Applications may help you pinpoint where performance issues lie with your startup.

JavaWS is downloading all the JARs in the background but there is no progress indication, which is very poor.

That is weird. How do you know it is the JAR download that is taking time? The JavaFX system ships with a default preloader which is supposed to show progress as the app jars are downloading (it's just a blue progress bar in the center of a white screen).

"The JavaFX system ships with a default preloader" Yes I remember we had that for some time, I think it was before we added

I downloaded the JavaFX 2.2.21 samples for OS X. Then went to the extracted sample directory and ran javaws Ensemble.jnlp and the standard preloader showed up with the blue progress bar as the app started up. Perhaps if you used similar packaging instructions to the Ensemble sample app, then things would work better for you.

Update

I just noticed the following reopened bug RT-25290 no default fx preloader for jnlp app . As I mentioned earlier, I don't actually encounter this bug and the default JavaFX Preloader shows for me on OS X (Java 8 build 88), so I'm not exactly sure under what situations you might encounter such a bug, but perhaps something to be aware of nonetheless.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM