Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 614
Franklin Bello Avatar asked Mar 03 '19 07:03

Franklin Bello


People also ask

How do I get JavaFX to work on VSCode?

Step 1: Install the Extension Pack for Java. Step 2: In Visual Studio Code, open the Command Palette (Ctrl+Shift+P) and then select the command Java: Create Java Project. Step 3: Select the option JavaFX in the list, follow the wizard, which will help you scaffold a new JavaFX project via Maven Archetype.

How do I fix JavaFX control not found?

To Solve error: module not found: javafx. controls Error You just need to add PATH_TO_FX. First of all Use %PATH_TO_FX% instead of $PATH_TO_FX in the command line. Then Recreate the variables for both system and user PATH_TO_FX enclosing its value in quotation marks.


1 Answers

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"/>
like image 172
José Pereda Avatar answered Oct 13 '22 00:10

José Pereda