I am starting to learn how to make GUI with JavaFx and I was following the basics to run a simple "hello world" program with the book 'JavaFx 9 by Example' from Carl Dea.
But in the end, even though I just copied the source code and the bash commands, javac doesn't acknowledge the javaFx packages.
This is not the first I code in Java, but it is the first time I am using the terminal in MacOs to compile it and run it.
At the same time I am learning JavaFx, I am also assimilating Bash. I read that MacOs have an old version of it; so I replace the one set up by default with a new version '5.0.7(1)-release'.
I do not know if it matters, but
$ echo "$BASH_VERSION"
5.0.7(1)-release.
and.
$ bash -version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17).
Also, I downloaded and installed the most recent version of Java some days ago
$ java --version
java 12.0.1 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)
It may have to do with the Java Path, but if it is that I am not sure how to solve it.
The problem I believe is when importing the javaFx libraries:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
When I compile it, I get several errors.
Some of them are:
$ javac -d classes src/*.java
src/HelloWorld.java:2: error: package javafx.application does not exist.
import javafx.application.Application;
^
Basically, it seems that javac does not recognize or knows the existence of any package from javaFx.
This error mitigates to the Objects that want to be created using this class
symbol: class Application
src/HelloWorld.java:20: error: cannot find symbol
public void start(Stage stage) {
^
Edit:
Thanks for the answers, i finally was able to do a simple application with JavaFx. The only thing that bothers me is the large command prompt needed for compiling this code.
$ javac --module-path $PATH_TO_FX --add-modules javafx.controls HelloWorld.java
$ java --module-path $PATH_TO_FX --add-modules javafx.controls HelloWorld
It does not go away, isn't it?