VS Code中JavaFX的launch.json配置失效,求解决方案
VS Code中JavaFX程序运行问题
环境信息
- JDK版本:17
- JavaFX SDK版本:17.0.9
- 开发环境:VS Code
已完成配置
- 已将JavaFX相关JAR文件添加至VS Code偏好设置
- 已配置
launch.json文件,内容如下:
{ // 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": [ { "type": "java", "name": "Current File", "request": "launch", "mainClass": "${file}" }, { "type": "java", "name": "App", "request": "launch", "mainClass": "App", "projectName": "testfx_1e12e64c", "vmArgs": "--module-path \"C:\\Program Files\\Java\\javafx-sdk-17.0.9\" --add-modules javafx.controls,javafx.fxml" } ] }
待运行代码
import javafx.application.Application; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class App extends Application { @Override public void start(Stage primaryStage) throws Exception{ Parent root = FXMLLoader.load(getClass().getResource("testfx.fxml")); primaryStage.setTitle("Hello World"); primaryStage.setScene(new Scene(root, 400, 300)); primaryStage.show(); } public static void main(String[] args) { launch(args); } }
已尝试的无效方案
- 将JavaFX文件夹迁移至无空格路径
- 更换JDK版本为21
问题仍未解决。
内容的提问来源于stack exchange,提问作者coaster_dude22
相关产品推荐
相关产品推荐

