Using Advanced Deployment Features
- Skill Level Advanced
- Product JavaFX
- Key Features Deployment
- Last Updated April 2009
This article explores additional features for deploying JavaFX applications available in the JavaFX SDK and the NetBeans IDE for JavaFX technology.
Many real-world applications retrieve data through web services, then parse and visualize them. For example, WeatherWidget application displays weather forecasts from the Yahoo! Weather RSS feed.
Passing Arguments to an Application
The WeatherWidget application enables a user to type the target location's ID in the text field and to covert degree values from Fahrenheit to Celsius by using the C/F button. Consider how you might pass this ID as an argument when deploying the application by using different deployment models. Try to pass the RSXX0091 id, which corresponds to St. Petersburg, Russia, and u=c to convert degree values from Fahrenheit to Celsius.
Stand-Alone Execution
This is the easiest model of deployment. All you need is to have a JAR file of your application and run it by using the following command:
javafx -cp WeatherWidget.jar Main RSXX0091&u=c
You must first ensure that you have the required JavaSE and JavaFX versions installed on your computer.
Web Start Execution
To deploy your application by using the Java Web Start software, create a JNLP file or modify the file that has been generated automatically by the NetBeans IDE. Add the application tag shown in the following code fragment to your JNLP file to pass the code argument when running the application.
<application-desc main-class="Weather">
<argument>code=RSXX0091&u=c</argument>
</application-desc>
</jnlp>
Run in Browser
Use the JavaScript programming language to call the javafx function and embed your application into a web page. Specify the code argument to pass the location ID as shown in the following code fragment.
<script src="http://dl.javafx.com/1.1/dtfx.js"> </script>
<script>
javafx(
{
draggable: true,
archive: "Weather.jar",
width: 200,
height: 200,
code: "Weather",
name: "Weather"
},
{
code: "RSXX0091&u=c"
}
);
</script>
Note that setting the draggable parameter to true enables dragging the applet to the desktop.
Running on the Mobile Emulator
Modify the automatically generated JAD descriptor to pass arguments to your application when you are running it on the mobile emulator. Add a line to specify the string value for the id argument, as shown in the following code fragment:
MIDlet-Name: Weather MIDlet-Version: 1.0 MIDlet-Vendor: Sergey Malenkov MicroEdition-Profile: JAVAFX-1.1 MicroEdition-Configuration: CLDC-1.1 MIDlet-1: Weather,,Weather_MIDlet MIDlet-Jar-URL: Weather.jar MIDlet-Jar-Size: 79095 id: RSXX0091&u=c
Parsing Arguments in the Application
Now consider parsing arguments in the application. Note that the browser and mobile deployment models pass arguments as key values. Use the following function to retrieve the value by using the key. This function returns null, if no value is set for this key.
var code = FX.getArgument("code");
You can use two methods to retrieve arguments when using the desktop model. First, you can define a global function named run:
function run(args: String[]) {
var code: Object;
for (arg in args) {
code = if (indexof arg > 0)
then "{code} {arg}"
else arg
}
println('code: {code}');
}
Second, you can use the following utility function:
def args = FX.getArguments();
These approaches differ only slightly. When using the first approach, all variables defined within the run function are local. For the second approach, all variables are global. Use the FX.getArgument function to receive a value by using a key, similar to the implementation in browser and mobile deployment models.
Related Links
- Tutorial: Deploy A Rich Internet Application Developed With JavaFX Technology
- Sample: Getting Weather Forecast from Yahoo!
We welcome your participation in our community. Please keep your comments civil and on point. You may optionally provide your email address to be notified of repliesyour information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.
Sergey Malenkov
Software Engineer, Sun Microsystems