Compiling and Running from the Command-Line (Getting a Jump Start in JavaFX)

We usually use an IDE to build and run JavaFX programs, but to take all of the mystery out of the process we use the command-line tools first.

■ Note For this exercise, as with most others in the topic, you need the source code. If you prefer not to type the source code into a text editor, you can obtain the source code for all of the examples in this topic from the code download site. See the Resources section at the end of this topic for the location of this site.

Assuming that you’ve downloaded and extracted the source code for this topic into a directory, follow the directions in this exercise, performing all of the steps as instructed. We dissect the source code after the exercise.

COMPILING AND RUNNING THE HELLO EARTHRISE PROGRAM FROM THE COMMAND

You’ll use the javafxc and javafx command-line tools to compile and run the program in this exercise. From the command-line prompt on your machine:

1. Navigate to the Hello directory.

2. Execute the following command to compile the HelloEarthRiseMain.java file.

javac -d . HelloEarthRiseMain.java

3. Because the -d option was used in this command, the class files generated are placed in directories matching the package statements in the source files. The roots of those directories are specified by the argument given for the -d option, in this case the current directory.


4. To run the program, execute the following command. Note that we use the fully qualified name of the class that will be executed, which entails specifying the nodes of the path name and the name of the class, all separated by periods.

java projavafx.helloearthrise.ui.HelloEarthRiseMain

The program should appear as shown in Figure 1-4 earlier, with the text scrolling slowly upward, reminiscent of the Star Wars opening crawls.

Congratulations on completing your first exercise as you explore JavaFX!

Next post:

Previous post: