2014-10-27 57 views
1

我使用Java Web Start啓動它的JavaFX應用程序。我試圖給它傳遞一個參數,但到目前爲止我一直沒有成功。我試圖按照部署工具包中給出的示例進行操作。所以這裏就是我現在所處的一切。將參數傳遞給javafx web start應用程序

HMTL:

<html> 
    <head> 
     <title>Parameter Testing</title> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
    </head> 
    <body> 
     <h1>Parameter Passing Test</h1> 
     <script src="http://java.com/js/dtjava.js"></script> 
     <script> 
      function launchApplication() { 
       dtjava.launch({url: 'ParamTesting.jnlp', params:{order: "852237"}}, {jvm: '1.7.0_72+', javafx: '2.2+'}, {}); 
       return false; 
      } 
     </script> 
     <a href='ParamTesting.jnlp' onclick="return launchApplication();"> 
      <img src="images/jws-launch-button.png" width="88" height="23"/> 
     </a> 
    </body> 
</html> 

JNLP:

<?xml version="1.0" encoding="UTF-8"?> 
<jnlp spec="1.0+" xmlns:jfx="http://javafx.com" href="ParamTesting.jnlp"> 
    <information> 
     <title>Param Testing</title> 
     <vendor>USGS</vendor> 
    </information> 
    <security> 
     <all-permissions/> 
    </security> 
    <update check="always" policy="always" /> 
    <resources> 
     <j2se version="1.7.0_72+" href="http://java.sun.com/products/autodl/j2se" /> 
     <jar href="ParamTesting.jar" main="true" version="0.1"/> 
     <property name="jnlp.versionEnabled" value="true"/> 
    </resources> 
    <application-desc name="ParamTesting"/> 
    <jfx:javafx-desc main-class="gov.usgs.tnm.paramtesting.MainApp" name="MainApp"> 
     <fx:param name="order" value="852237"/> 
    </jfx:javafx-desc> 
</jnlp> 

JavaFX的入手方法:

public void start(Stage stage) throws Exception { 
    System.out.println(getParameters().getNamed().get("order")); 

    Parent root = FXMLLoader.load(getClass().getResource("/fxml/Scene.fxml")); 

    Scene scene = new Scene(root); 
    scene.getStylesheets().add("/styles/Styles.css"); 

    stage.setTitle("Parameter Testing"); 
    stage.setScene(scene); 
    stage.show(); 
} 

每次我運行此,「N你會被打印在控制檯上。我無法弄清楚我要去哪裏錯了。

此外,此應用程序確實有一個與它關聯的訂單系統,因此參數需要是動態的。如果有人對我如何能夠做到這一點有任何洞見,它將不勝感激。

回答

0

我發現我的問題。我不需要JNLP中的application-describe元素。我不知道爲什麼在那裏導致參數不能被JavaFX程序訪問,但它確實如此。

相關問題