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.
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"/>