2013-07-08 54 views
0

有没有办法找出Javafx2应用程序如何启动?如何确定JavaFX应用程序是否由WebStart运行?

I.E.是通过web启动链接启动还是通过桌面快捷方式启动?

我需要知道该应用是从web start还是桌面图标启动的原因是,有些参数是通过JNLP传递的,应用程序在从桌面图标启动时没有使用,并且没有其他方式那个(我知道)应用程序会知道这些参数是否通过。

任何指针都会有帮助。

+0

感谢您编辑Sergey的问题。现在看来似乎更加明显。我会尝试一下你在下面建议的想法。会及时向大家发布。 – Aspirant

+0

我尝试了下面列出的前两种方法:即从PersistenceService读取一个属性(如:hasRunOnce)并阅读WebContext和SecurityManager,但由于某个问题或其他问题没有解决问题。专家,如果你能想到其他方法,请告诉我。 – Aspirant

回答

0

AFAIK,没有好的方法,你需要使用运行模式的副作用。

您可以选择使用下一者:

  1. 小程序总是有WebContext
  2. 的Applet/JNLP总是有安全管理器
  3. 桌面运行通常没有安全管理器(不完全可靠)和从来没有WebContext

参见下面的代码:

Pane root = new VBox(5); 

    boolean gotSecurityManager = System.getSecurityManager() != null; 
    boolean gotWebContext = getHostServices().getWebContext() != null; 

    root.getChildren().addAll(
      new Label("desktop = " + (!gotSecurityManager && !gotWebContext)), 
      new Label("jnlp = " + (gotSecurityManager && !gotWebContext)), 
      new Label("applet = " + gotWebContext) 
      ); 

    Scene scene = new Scene(root, 500, 250); 

    primaryStage.setTitle("Hello World!"); 
    primaryStage.setScene(scene); 
    primaryStage.show(); 

另一种选择是Can I find out if the java program was launched using java or javaw

+0

我试过上面的解决方案。但我试图从桌面上创建的快捷方式启动应用程序,它仍然显示为通过jnlp启动。也许我错误地说了我的问题。请指教。 – Aspirant

+0

或者桌面上的快捷方式可能只是模仿行为,就好像应用程序来自网站,因为它在内部使用jnlp文件启动应用程序。 – Aspirant

+0

哦,桌面快捷方式,对不起,我误解了一个问题 –

0

(ME)..它只会从一个单一的(第一个)时间桌面图标启动?

是的,这是正确的。

好的。这是可行的。

在代码中,使用JNLP API的PersistenceService来检查键/值(例如,has-run-once/true)。如果存在而不是,则使用JNLP中定义的属性并设置该值。

这是一个小的demo. of the PersistenceService

相关问题