问题描述
我的IDE是eclipse,我的项目是一个独立的javaFX应用程序(纯CS架构与OSGI框架)。如何使用Preloader,因此预加载程序将在我的主要应用程序之前启动并隐藏?
我在
中找到一些代码
但是我仍然不知道如何在OSGI框架中使用我的启动应用程序来部署Preloader。
我给我下面的启动应用程序的一些代码:
public class MyPrjMain extends Application {
private static舞台一级
public void start(final Stage stage)throws BusinessException {
primaryStage = stage;
init(primaryStage);
primaryStage.show();
}
}
非常感谢大家。
这是一个很长的答案,不耐烦的快速回答是下载这个,并查看它是否适合您的情况。
我的回答提供了有关样式功能在JavaFX。您的问题在Eclipse和OSGI环境中具体提到 Preloader
的用法,但是我不会直接解决这种情况,因为我不使用这些技术。希望一般信息仍然适用于您的方案。
1。 Java在Java启动时具有显示启动页面的本地支持。
- 这可以使用
-splash:< image>
。
优点和缺点:
+
获取独立应用程序以显示快速图像的最简单方法。
+
可以非常快速地显示
=>它是对VM进程的输入参数,所以(可能)即使在VM本身完全初始化之前也可以显示。
-
有限的功能
=>只允许显示图像,而不是其他预加载器功能,如报告初始化进度,动画,登录提示等(除非您)。
2。预加载器可用于独立应用程序。
在 9.3.4使用预加载器显示应用程序初始化进度
的一节中有一个例子。本教程提供 LongInitAppPreloader
和 LongInitApp
类中的可执行示例代码(使用我在此答案中提供的类名称作为一个
示例独立应用程序具有很长的初始化时间和自定义的预加载器
提供有关初始化进度的反馈。该示例通过与一个 Thread.sleep
调用,但一个真正的应用程序将会做一些建立网络连接,检索和解析网络数据并设置初始应用程序的方式。
预加载器不是特定于小应用程序和WebStart的,而是主要针对这些部署类型。小程序和WebStart初始化过程比独立的应用程序初始化更复杂,所以Preloader文档的大部分都专门用于那些更复杂的场景。
3。您不需要将预加载器放在单独的JAR中。
您可以放置 Preloader
与您的类相同的JAR。对于通过网络加载协议动态部署和更新的大型应用程序,如,将 Preloader
在单独的JAR中是有道理的。对于执行基于网络的初始化的独立应用程序,它可能没有太大的区别,可以跳过单独的打包步骤来简化构建和部署过程。
4。您可以在不使用预加载器的情况下实现预加载器样式功能。
预加载器功能的很多(并非全部)功能可以在不进行子类化的情况下实现。
您可以:
- 创建启动在您的应用程序的方法。
- 放置快速图像,然后将启动阶段。
- 有一个背景
- This works using the
-splash:<image>
VM switch. - Create a startup Stage in your application's start method.
- Place a splash image and ProgressBar in the startup stage.
- Have a background task for lengthy application initialization processes.
- Report initialization progress back to your startup stage from your background task.
- On initialization completion, either:
- a. Replace the startup stage with a newly created application stage OR
- b. Replace the contents of the scene in the startup stage with a new scene for your application.
- Code to displays a JavaFX splash page for an intensive startup task with progress monitoring
- JavaFX standalone application Splash Page for a great website
在不使用 Preloader
的情况下,在JavaFX中显示进度监视启动屏幕的相关示例代码是:
上述代码可以重构使用预加载器在这种情况下,存在用于通知应用程序初始化事件和更灵活的部署模型的良好定义的框架(例如,单独的jar中的预加载器)可用。但是,使用 Preloader
可能有点复杂。对于某些实现,了解 Preloader
框架可能不值得。
5。 WebStart应用程序对Splash Images有JNLP支持
(这一点是非常无关紧要的,仅供参考)。
我相信在启动webstart应用程序时显示启动映像,但是我从来没有能够使该标志在JavaFX 2应用程序中工作,只能在Swing应用程序中运行,即使这样也不是可靠的,因为它只会显示第二次申请被推出。
My IDE is eclipse and my project is a stand-alone javaFX application(pure CS architecture with OSGI framework).
How to use Preloader thus the preloader would be started before my main Application and hid later?
I found some code inhttp://docs.oracle.com/javafx/2/deployment/preloaders.htm#BABGGDJG
But I still don't know how to deploy the Preloader with my startup Application in a OSGI framework.I give some code of my startup application below:
public class MyPrjMain extends Application {
private static Stage primaryStage;
public void start(final Stage stage) throws BusinessException {
primaryStage = stage;
init(primaryStage);
primaryStage.show();
}
}
Thanks very much, everybody.
This is a long answer, the quick answer for the impatient is to download this sample code for displaying a splash page for an intensive startup task and see if it is adaptable to your situation.
My answer provides general information about Preloader style functionality in JavaFX. Your question specifically mentions Preloader
usage in an Eclipse and OSGI environment, but I won't directly address that scenario as I don't use those technologies. Hopefully the general information is still applicable to your scenario.
1. Java has native support for displaying a splash page when Java is started.
Advantages and disadvantages:
+
The simplest way to get your standalone application to show a splash image.
+
Can be displayed very quickly => it's an argument input to the VM process, so (presumably) it can be displayed even before the VM itself has fully initialized.
-
Has limited features => only allows display of an image, not other preloader features such as reporting of initialization progress, animation, login prompts etc (unless you make use of AWT APIs)
-
Won't work on all platforms until Java 8 (see issue Mac: Impossible to use -splash: with JavaFX 2.2 and JDK 7).
2. Preloaders may be used for standalone applications.
The JavaFX Preloader tutorial has an example in the section 9.3.4 Using a Preloader to Display the Application Initialization Progress
. The tutorial provides executable sample code in the LongInitAppPreloader
and LongInitApp
classes (use the class names I provide in this answer as one name in the tutorial is currently wrong).
The sample standalone application has a long initialization time and a custom Preloader
provides feedback on the progress of the initialization. The sample simulates the long initialization through a Task with a Thread.sleep
call, but a real application would be doing something like establishing network connections, retrieving and parsing network data and setting up the initial application Scene.
Preloaders are not specific to applets and WebStart, but are primarily targeted to those deployment types. The applet and WebStart initialization process is more complex than standalone application initialization, so much of the Preloader documentation is devoted to those more complex scenarios.
3. You don't need to place a Preloader in a separate JAR.
You can place the Preloader
in the same JAR as your Application class. For large applications dynamically deployed and updated over network loading protocols such as WebStart, placing the Preloader
in a seperate JAR makes sense. For standalone applications performing network based initialization, it probably doesn't make much difference and the separate packaging step could be skipped to simplify the build and deployment process.
4. You can achieve Preloader style functionality without using a Preloader.
Much (not all) of the Preloader functionality can be achieved without subclassing Preloader.
You can:
5b is probably preferred so that you don't need to create multiple windows.
For examples of this strategy, see my answers to the following questions:
The related sample code for displaying Progress Monitoring splash screens in JavaFX without using a Preloader
is:
The above code could be refactored to use a Preloader subclass instead, in which case there is a well defined framework for notification of application initialization events and more flexible deployment models (e.g. preloader in seperate jar) are available. However use of a Preloader
may be a little complicated. For some implementations, it may not be worth the time to understand the Preloader
framework.
5. WebStart Apps have JNLP support for Splash Images
(this point is pretty irrelevant and just included for completeness).
I believe that webstart applications can have a flag in their jnlp file to show the startup image as the webstart application launches, but I've never been able to get that flag to work in a JavaFX 2 application, only in a Swing application and even then it wasn't all that reliable as it would only display the second time the application was launched.
这篇关于如何在Eclipse中使用javaFX Preloader与独立应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!