我的应用程序是由 JavaWS 部署的,但是在用户单击 JNLP 后,会出现很长的停顿,似乎什么也没发生,然后应用程序就会在屏幕上弹出。JavaWS 正在后台下载所有 JAR,但没有进度指示,非常糟糕。所以我开始构建一个自定义的:
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));
}
}
下面是我的 JNLP。您会注意到我尝试以三种不同的方式使用自定义加载器类,它们都不能单独工作或组合在一起:
<?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>
所以这一切都没有任何区别。即使有完整的日志记录+跟踪,也没有任何有趣的内容打印到控制台。
到底是怎么回事?