29

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

2
  • Possible duplicate of Module javafx.controls not found in Java 9 Commented Jan 5, 2019 at 22:09
  • 3
    Downloading and unpacking the JavaFX files (gluonhq.com/products/javafx) worked for me. I have the following VM options: --add-exports=javafx.base/com.sun.javafx.reflect=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.javafx.util=ALL-UNNAMED --module-path /opt/javafx-sdk-11.0.2/lib/ --add-modules=javafx.controls,javafx.media,javafx.fxml Commented Jul 11, 2019 at 19:44

14 Answers 14

11

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! On the Mac I had to adjust slightly: --module-path $PATH_TO_FX:$PATH_TO_FX/lib
4

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'

Comments

4

The problem was solved in 3 steps.

  1. Use %PATH_TO_FX% instead of $PATH_TO_FX in the command line.

  2. Recreate the variables (both system and user) PATH_TO_FX enclosing its value in quotation marks. As the directory "C:\Program Files\Java\javafx-sdk-11.0.1\" contains a space, it caused an error "invalid flag".

  3. Rebooting the computer to update the variables.

Comments

4

Make sure you don't have spaces in your list of modules:

--module-path PATH_TO_JAVAFX/lib --add-modules javafx.swing,javafx.graphics,javafx.fxml,javafx.media,javafx.controls

Comments

3

Since I use Maven, I had to modify the pom.xml file to include the dependency.
pom.xml:

<dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>13.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>11.0.2</version>
        </dependency>
</dependencies>

You may need to modify the version numbers according to what version you have installed.

1 Comment

Might need to add javax-web dependency also in pom.xml in the same way.
1

As JavaFX isn't included in "default" JDK's I found the easiest fix for this kind of issues is to use the LibericaJDK (11+) from Bellsoftware which has the JavaFX included again to make it easier to develop and run JavaFX applications.

https://bell-sw.com/pages/java-11.0.4/

Comments

0

helloFX.bat @echo off cls set PATH_TO_FX="C:\Program Files\Java\javafx-sdk-11.0.2\lib" C: cd \development\java\javaFX

rem javac --module-path %PATH_TO_FX% --add-modules javafx.controls,javafx.fxml HelloFX.java javac --module-path %PATH_TO_FX% --add-modules javafx.controls HelloFX.java

java --module-path %PATH_TO_FX% --add-modules javafx.controls HelloFX

pause

1 Comment

Would you add some expression? It is actually hard to follow with only command line example, thanks.
0

When running the command

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

instead of writing the $PATH_TO_FX or %PATH% write the path itself that is

javac --module-path C:\javafx-sdk-11.0.2\lib --add-modules javafx.controls HelloFX.java

Also try to make sure your directory doesn't have any spaces. It gave me problems, it may work for you for a directory with spaces

1 Comment

can we run that javac under netbeans configuration anyway? @r_goyal?
0

My solution was little different from above:
javac --module-path C:\other_program\javafx-sdk-17.0.1\lib\ --add-modules javafx.controls HelloFX.java
I had to put lib in the path, and not C:\other_program\javafx-sdk-17.0.1\ together like Arilou suggestion.

To execute the compiled file, "HelloFX.class", you may include the lib path as well:
java --module-path C:\other_program\javafx-sdk-17.0.1\lib\ --add-modules javafx.controls HelloFX

Runtime environemnt:
  OS: Windows 10
  PowerShell
  Java 15.0.1
  JavaFX 17.01

Comments

0

I am using maven. I had to add this dependency.

    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>19-ea+2</version>
    </dependency>

Comments

0

Follow these steps:

  1. Download and install the JavaFX SDK from the official OpenJFX website: https://openjfx.io/

  2. In IntelliJ, open your project and go to File > Project Structure.

  3. Select "Modules" from the left-hand side and then click the "+" button to add a new module.

  4. Select "JARs or directories" and browse to the "lib" folder in your JavaFX SDK installation directory.

  5. Select all the JAR files in the "lib" folder and click "OK".

  6. IntelliJ will now add the JAR files to your project's classpath.

This should do the job....This is for IntelliJ but this works for other IDEs as well or at least in a similar way..

Comments

0

import javafx.application.Application;

import javafx.scene.Group;

import javafx.scene.PerspectiveCamera;

import javafx.scene.Scene;

import javafx.scene.paint.Color;

import javafx.scene.paint.PhongMaterial;

import javafx.scene.shape.Box;

import javafx.stage.Stage;

public class Echelon3D extends Application {

private static double\[\]\[\] matrix = {

    {2, 4, -2},

    {-2, -5, 4},

    {4, 9, -6}

};

public static void main(String\[\] args) {

    convertToEchelonForm(matrix);

    launch(args);

}

@Override

public void start(Stage stage) {

    Group root = new Group();

    int rowOffset = 50, colOffset = 50, scale = 10;

    for (int i = 0; i \< matrix.length; i++) {

        for (int j = 0; j \< matrix\[i\].length; j++) {

            double value = matrix\[i\]\[j\];

            Box box = new Box(20, 20, Math.abs(value) \* scale);

            box.setTranslateX(j \* rowOffset);

            box.setTranslateY(i \* colOffset);

            box.setTranslateZ(-value \* scale / 2);

            PhongMaterial material = new PhongMaterial();

            material.setDiffuseColor(value \>= 0 ? Color.BLUE : Color.RED);

            box.setMaterial(material);

            root.getChildren().add(box);

        }

    }

    Scene scene = new Scene(root, 600, 600, true);

    scene.setFill(Color.LIGHTGRAY);

    PerspectiveCamera camera = new PerspectiveCamera(true);

    camera.setTranslateZ(-300);

    scene.setCamera(camera);

    stage.setTitle("3D Row Echelon Form Visualization");

    stage.setScene(scene);

    stage.show();

}

public static void convertToEchelonForm(double\[\]\[\] matrix) {

    int rows = matrix.length;

    int cols = matrix\[0\].length;

    for (int i = 0; i \< rows; i++) {

        double divisor = matrix\[i\]\[i\];

        if (divisor != 0) {

            for (int j = 0; j \< cols; j++) {

                matrix\[i\]\[j\] /= divisor;

            }

        }

        for (int k = i + 1; k \< rows; k++) {

            double factor = matrix\[k\]\[i\];

            for (int j = 0; j \< cols; j++) {

                matrix\[k\]\[j\] -= factor \* matrix\[i\]\[j\];

            }

        }

    }

}

}

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

I fixed the issue by using CMD instead of Powershell.

Comments

-1

If you are using Netbeans, its a must to uncheck "Compile on Save", unless you get this error.

https://github.com/openjfx/openjfx-docs/issues/91#issuecomment-537354974

If you want a screenshot

https://github.com/openjfx/openjfx-docs/issues/120#issuecomment-692805305

1 Comment

Please add explanation to your answer instead of just providing links

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.