JavaFX-11 in VSCode: Error: Could not find or load main class Files\Java\javafx-sdk-11.0.2\lib
Asked Answered
K

3

7

I have been trying to set up JavaFX-11 in Visual Studio Code.

I found this post JavaFX-11 with VSCode, which explained how to do so, and followed the steps.

However, I need to include the module-path to the JavaFX SDK by adding an entry for the vmArgs in the launch.json file:

{
"configurations": [
    {
        "type": "java",
        "name": "CodeLens (Launch) - Main",
        "request": "launch",
        "vmArgs": "--module-path C:\\Program Files\\Java\\javafx-sdk-11.0.2\\lib --add-modules javafx.controls,javafx.fxml",
        "mainClass": "hellofx.Main",
        "projectName": "hellofx"
    }
]

}

As you can see in the vmArgs entry, is my local path to the JavaFX SDK. However, when I try to run the program I get the following error:

Error: Could not find or load main class Files\Java\javafx-sdk-11.0.2\lib Caused by: java.lang.ClassNotFoundException: Files\Java\javafx-sdk-11.0.2\lib

For the past hours I have trying to figure out why it doesn't work. Am I writing the arguments wrong? I saw there are .jmods files. Should I download those files? Is there any other way to specify the module path?

Is worth to mention that I am running Visual Studio Code in Windows 10, so I have to use escape sequence to use backslashes.

Kiaochow answered 3/3, 2019 at 7:45 Comment(0)
P
15

As you can see by the error you have posted:

Error: Could not find or load main class Files\Java\javafx-sdk-11.0.2\lib

it is clear that the issue is related to the space you have in Program Files.

Solutions

As a possible solution, you could move your JavaFX SDK to a folder without spaces in its path, and set your vmArgs accordingly, like:

"vmArgs": "--module-path C:\\Java\\javafx-sdk-11.0.2\\lib --add-modules javafx.controls,javafx.fxml",

While that works, if you still want to keep your current approach, you have to find a way to set the path with spaces.

Based on a similar issue, you can find that:

Paths containing spaces should be surrounded by (escaped) double quotes

So this will be the solution in your case:

"vmArgs": "--module-path \"C:\\Program Files\\Java\\javafx-sdk-11.0.2\\lib\" --add-modules javafx.controls,javafx.fxml",

Note this doesn't apply to the path added in the .classpath file with the JavaFX jars, that will be like this:

<classpathentry kind="lib" path="C:\\Program Files\\Java\\javafx-sdk-11.0.2\\lib\\javafx.base.jar"/>
Pater answered 3/3, 2019 at 13:13 Comment(1)
Alternate solution would be to use the environment variable PROGRA~1 that delegates to Program Files. e.g. --module-path C:\\PROGRA~1\\Java\\javafx-sdk-11.0.2\\lib. UNLESS VSCode doesn't support the variables (?)Supralapsarian
B
0

Adding double quotes surrounding my environment variable in IntelliJ solved for me:

PATH_TO_FX="C:\Program Files\Java\javafx-sdk-11.0.2\lib"
Bidden answered 7/1, 2021 at 6:43 Comment(0)
L
-1

** If you are having this error on Eclipse** "Error occurred during initialization of boot layer java.lang.module.FindException: Module javafx.controls not found"

Remove the JavaFX SDK library from the build path of the project!!

Liberal answered 31/3, 2021 at 23:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.