I saw several answers for this question, but none of them solved my problem. I followed this tutorial to create a simple JavaFX application with a button. At first, it worked totally fine. But, when I close VS Code and open it again it shows the error:
Error: JavaFX runtime components are missing, and are required to run this application
I added vmArgs to my launch.json file:
"vmArgs": "--module-path \"C:/Program Files/Java/javafx-sdk-19/lib\" --add-modules javafx.media,javafx.base,javafx.graphics,javafx.controls,javafx.fxml"
This is the Java code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(Stage primaryStage) {
Button btOK = new Button("OK");
Scene scene = new Scene(btOK, 200, 250);
primaryStage.setTitle("MyJavaFX");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) throws Exception {
Application.launch(args);
}
}
This is the launch.json file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Java",
"type": "java",
"request": "launch",
"stopOnEntry": true,
"jdkPath": "${env:JAVA_HOME}/bin",
"cwd": "${fileDirname}",
"startupClass": "${fileBasenameNoExtension}",
"classpath": [
".",
"${fileDirname}"
]
},
{
"name": "Java Console App",
"type": "java",
"request": "launch",
"stopOnEntry": true,
"jdkPath": "${env:JAVA_HOME}/bin",
"cwd": "${fileDirname}",
"startupClass": "${fileBasenameNoExtension}",
"classpath": [
".",
"${fileDirname}"
],
"externalConsole": true
},
{
"type": "java",
"name": "Launch Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "Launch App",
"request": "launch",
"mainClass": "App",
"projectName": "bookFirst_4a14754a",
"vmArgs": "--module-path \"C:/Program Files/Java/javafx-sdk-19/lib\" --add-modules javafx.media,javafx.base,javafx.graphics,javafx.controls,javafx.fxml",
}
]
}
Here are the screenshots if required: launch.json