I have a very simple menu program I have made in JavaFX on Visual Studio Code, the code works fine on its own, but after merging with a larger project, the code refuses to work. Giving me a "JavaFX runtime components are missing, and are required to run this application" error.
I’ve tried updating the launch.json, moving the Javafx files into a subfolder, and moving the javafx files into a seperate folder to test them, all of which didn’t work.
Here’s the Menu file
import java.io.IOException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class Menu extends Application {
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("fullscrn.fxml"));
Parent root = fxmlLoader.load();
Scene scene = new Scene(root);
stage.initStyle(StageStyle.UTILITY);
stage.setResizable(false);
stage.show();
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
and the Launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Menu",
"request": "launch",
"mainClass": "Menu",
"projectName": "Menutst_8fc80d72"
},
{
"type": "java",
"name": "Main",
"request": "launch",
"vmArgs": "--module-path "C:/Users/lukas/OneDrive/Desktop/javafx-sdk-22.0.1" --add-modules javafx.controls,javafx.fxml",
"mainClass": "Main",
"projectName": "Menutst_8fc80d72",
},
{
"type": "java",
"name": "Current File",
"request": "launch",
"mainClass": "App",
"args": ""
}
]
}
C:/users… is where my main install of the Javafx libs is kept. I also tried using the project lib folder of JavaFX (the one that is kept with the other code files) and that changed nothing as well.
2
Answers
These two pieces of code in the Launch.Json were messing with the JavaFX stuff. Deleting them had no adverse effect on the rest of the code and everything is running smoothly now. I also forgot to add /lib into the filename.
So that was the problem! Thanks to everyone who helped me out.
Your
--module-path
is wrong. For the JavaFX Windows SDK, the modules are in thelib
directory under the SDK installation.1Change:
To:
This is documented in the openjfx getting started instructions for JavaFX in Visual Studio Code, section "Non-modular from the IDE" part 4 "Create and update launch configurations".
I do recommend using a build tool (Maven or Gradle) rather than manually configuring the IDE like this. The getting started documentation I linked tells you how to integrate a build tool with your IDE. Alternatively, you can use a Java distribution that includes JavaFX (e.g. Bellsoft Liberica "Full JDK" or Azul Zulu "JDK FX"), then you don’t need to worry about setting module paths.
bin
directory where native components (.dll
) are placed, but the Mac SDK places native components (.dylib
) in thelib
directory where the jars are. So there could be some differences in the setup requirements for these two distributions.