简体   繁体   中英

Passing parameters from JNLP to JavaFX2

I'm trying to pass a parameter defined in a JNLP file to my JavaFX 2 app. I thought this would be straight forward but I do not seem to able to get it to work. I've read alot already on the topic but without success.

This is a part of the JNLP file where the parameter is defined:

...
<applet-desc  width="800" height="600" main-class="com.javafx.main.NoJavaFXFallback"  name="Module" >
    <param name="requiredFXVersion" value="2.2+"/>
    <param name="key1" value="value1"/>
</applet-desc>
...

I try to read the parameters in the JavaFX 2 app with following code:

@Override
public void start(Stage stage) throws Exception {
    System.out.println("key1 = " + getParameters().getNamed().get("key1"));
    ...
}

However, if I clean and build the project and start it through the JNLP file, I check the Java Console and get:

key1 = null

Any ideas what the problem could be? Thanks in advance..

<applet-desc  width="800" height="600" main-class="com.javafx.main.NoJavaFXFallback"  name="Module" >
    <param name="requiredFXVersion" value="2.2+"/>
    <param name="key1" value="value1"/>
</applet-desc>

AFAIK the applet-desc element is only used when there is no javafx-runtime available. Pointing main-class to com.javafx.main.NoJavaFXFallback means you dont provide a pre-javafx version of your applet.

Instead the real main-method and it's params are pointed out by below element instead:

<jfx:javafx-desc  width="960" height="720" main-class="brickbreaker.Main"  name="BrickBreaker" >
    <fx:param name="sampleParam" value="Built with 1.7.0_17"/>
    <fx:param name="noValueParam"/>
    <fx:argument>Arg1</fx:argument>
    <fx:argument>Arg2 with spaces </fx:argument>
</jfx:javafx-desc>

JavaFX applications support two types of application parameters: named and unnamed (see the API for Application.Parameters).

Static named parameters can be added to the application package using and unnamed parameters can be added using . They are applicable to all execution modes including standalone applications.

source: http://docs.oracle.com/javafx/2/deployment/packaging.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM