I received a query on how to pass arguments in JavaFX. It basically depends on how we deploy the application. The application can be deployed using JavaWebStart, as an applet or launched from command line.

Lets take a simple application..

var text = Text {
    x: 10, y: 30
    font : Font size : 16 }
    content: "Argument {FX.getArgument( "key" )}"
}

The argument is passed as key-value pair. The value is retrieved using FX.getArgument( <key> ) method. Arguments can be passed to various deployment modes as shown below.

Command Line:

javafx -cp FXArguments.jar fxarguments.Main key="From Command Line"


Applet:

<script src="http://dl.javafx.com/1.2/dtfx.js"></script>
<script>
    javafx(
        {
              archive: "FXArguments.jar",
              draggable: true,
              width: 250,
              height: 80,
              code: "fxarguments.Main",
              name: "FXArguments",
              key: "from Applet"
        }
    );
</script>

Launch Applet Example


Java Web Start:

<jnlp spec="1.0+" codebase="dist" href="FXArguments.jnlp">
    <application-desc main-class="com.sun.javafx.runtime.main.Main">
        <argument>MainJavaFXScript=fxarguments.Main</argument>
        <argument>key=from Java Web Start</argument>
    </application-desc>
</jnlp>

Launch Web Start Example

Source:



Comments:

Is it also possible to pass in an argument as a URL parameter for a web start application?

Like this:
www.test.com/app.jnlp?key=arg1&test=other

/Pär

Posted by Pär Dahlberg on June 13, 2009 at 03:26 PM IST #

@Pär Dahlberg That wont be possible. One way is to write a servlet with content-type as XML which will dynamically generate the jnlp file. This way we can pass the arguments to servlet which returns the required jnlp file.

Posted by Rakesh Menon on June 14, 2009 at 10:58 AM IST #

Hadn't thought of that. Thanks :)

/Pär

Posted by Pär Dahlberg on June 23, 2009 at 01:42 AM IST #

i'm just looking for this, thanks a lot Rakesh!

Posted by LaoZhang on June 25, 2009 at 08:36 AM IST #

@LaoZhang Glad! Thanks!

Posted by Rakesh Menon on June 25, 2009 at 11:48 AM IST #

How do I pass jvm arguments to the applet? I'm running up against a problem with localization and cant' figure how to translate this

-Duser.language=fr -Duser.country=CA

in to something that can be used by the applet. I've tried adding

<param name="java_arguments" value="-Duser.language=fr -Duser.country=CA"/>

inside the <applet-desc> tag inside the jnlp file, but no luck.

thanks

Posted by Sean C on October 26, 2009 at 11:55 PM IST #

@Sean C You can use property tag inside resources in jnlp to set System properties.

<property name="key" value="overwritten"/>

There are some security restrictions for unsigned applets.

Please refer to jnlp syntax for more info : http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html#resources

Posted by Rakesh Menon on October 27, 2009 at 12:30 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed

This blog copyright 2009 by Rakesh Menon