Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: javafx.controls

Tags:

java

I have downloaded JavaFX SDK, unpacked it and set a PATH_TO_FX system variable, following this instructions. I used following code example:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class HelloFX extends Application {

    @Override
    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
        Scene scene = new Scene(new StackPane(l), 640, 480);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}

Tried to compile it with the suggested pattern:

javac --module-path $PATH_TO_FX --add-modules javafx.controls HelloFX.java

But compiler throws an error: module not found: javafx.controls. Windows 10. Java and JavaFX versions is 11.0.1

Again: I DID ADD the line --add-modules javafx.controls

like image 794
Oksana Oryekhovska Avatar asked Jan 05 '19 19:01

Oksana Oryekhovska


2 Answers

I had to also include the 'lib' directory: --module-path %PATH_TO_FX%;%PATH_TO_FX%\lib to make it compile.

like image 174
Arilou Avatar answered Sep 29 '22 02:09

Arilou


I'm using gradle and below build.gralde works fine for me (org.beryx.jlink is optional to build standalone distribution).

plugins {
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.5'
    id "org.beryx.jlink" version "2.3.0"  //optional for jlink
}

repositories {
    mavenCentral()
}

javafx {
    modules = [ 'javafx.controls' ]
}

mainClassName = 'gui.Main'
like image 41
Leon Avatar answered Sep 29 '22 03:09

Leon