1

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?

  • 1
    You might want to take a look at this `https://www.infoworld.com/article/3305073/removed-from-jdk-11-javafx-11-arrives-as-a-standalone-module.html`. Since you are using Java 12, you would have to download JavaFX SDK separately. Just downloading Java SDK won't probably work. You can use this one `https://openjfx.io/openjfx-docs/` for Java FX 12 or you can download from here `https://www.oracle.com/technetwork/java/javafx/install-javafx-sdk-1-2-139156.html`. Let us know how it goes. – Ashish Jun 19 '19 at 04:26
  • As already mentioned, JavaFX was removed from the JDK in Java 11 and is now a third party library. You need to include that library when compiling/running your project. See [Getting Started with JavaFX](https://openjfx.io/openjfx-docs/). – Slaw Jun 19 '19 at 04:50
  • This will link help you creating a hello world javaFx example. https://openjfx.io/openjfx-docs/#install-javafx – Pie Jun 19 '19 at 10:02
  • "It does not go away, isn't it?" - No idea what you are asking here. Or even if that is a real question or a rhetorical question. – Stephen C Jun 20 '19 at 01:09

0 Answers0