How to handle java web start (jnlp) downloading progress in a preloader?

怎甘沉沦 提交于 2019-12-03 01:12:11

I have been fighting with this too, recently. I switched back to the (ugly) default preloader (as that one shows up nicely) until I find some more time to investigate this.

If you enable Java Webstart full tracing

"<JAVA_HOME>\bin\javaws.exe" -userConfig deployment.trace true
"<JAVA_HOME>\bin\javaws.exe" -userConfig deployment.trace.level all

you should see preloader messages which should give you some information about what is going on. In my case I could see a lot of messages like these

preloader: Added pending event 2: DownloadEvent[type=load,loaded=0, total=62791, percent=0]

indicating that the custom preloader hasn't been verified/started yet but download events were already coming in.

What happens if you switch <update check="background"/> to <update check="always"/>?

EDIT

This is my test JNLP. Seems like you're missing to specify the JavaFX runtime resource?

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" xmlns:jfx="http://javafx.com" codebase="http://localhost:8080/HelloWorldFX" href="HelloWorldFX.jnlp">
  <information>
    <title>HelloWorldFX</title>
    <vendor>Unknown</vendor>
    <description>HelloWorldFX</description>
    <offline-allowed/>
  </information>
  <resources os="Windows">
        <jfx:javafx-runtime version="8.0+"/>
    </resources>
  <resources>
    <j2se version="1.8+" href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="HelloWorldPreloader.jar" size="10774" download="progress" />
    <jar href="HelloWorldFX.jar" size="248884114" download="eager" main="true" />
  </resources>
  <jfx:javafx-desc  width="600" height="400" main-class="sample.Main"  name="HelloWorldFX"  preloader-class="HelloWorldPreloader"/>
  <update check="always"/>
</jnlp>
nhylated

Note: I haven't tested or executed the code; my answer is primarily based on looking at the code. I haven't worked on JavaFX but I can grasp the code since I've worked on Swing and JNLP before.

The first thing I notice, is that in Phase 2, the default JavaFX preloader handling the downloading of the application JARs is not showing.

This seems to be because of the PreloaderFX.start(stage) method. The stage passed as the method's argument remains empty because the method constructs a new Stage() and adds children to it. If you add the child elements to the method's argument, it should display your custom preloader/progressbar during phase 2.

If the code still doesn't work as expected after this, I'd try debugging all the logic/code associated with the noLoadingProgress flag. Try commenting all that out (essentially taking noLoadingProgress out of the picture) and see if it fixes the issue.

Also, even though you've got this right in your code, see this answer - according to which all ProgressNotifications are handled by the handleApplicationNotification method.

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!