JavaFX在IntelliJ与VS Code中无法使用的配置求助
Got it, let's get your IntelliJ IDEA and VS Code set up for JavaFX so you can ditch those tedious command-line commands. Here's the straightforward, step-by-step configuration for both IDEs:
IntelliJ IDEA 配置方法
- Open your IntelliJ IDEA, create a new JavaFX project or open your existing school project.
- Go to File → Project Structure (or use the shortcut
Cmd + ;on macOS). - In the left sidebar, select Project:
- Make sure the Project SDK is set to your installed
jdk-11.0.2.jdk. - Set Project language level to
11 - Local variable syntax for lambda parameters.
- Make sure the Project SDK is set to your installed
- Next, select Libraries in the left sidebar:
- Click the
+icon → choose Java, then navigate to thelibfolder of your JavaFX SDK (e.g.,/Library/Java/JavaVirtualMachines/javafx-sdk-11.0.2/lib). Select the folder itself, then click OK to add it as a library.
- Click the
- Now configure the run environment:
- Click the run configuration dropdown in the top-right corner → select Edit Configurations.
- Choose your JavaFX main class's run configuration (or create a new one if needed).
- In the VM options field, paste this line (adjust the path if your JavaFX SDK is in a different location):
Note: If you don't use FXML in your project, you can remove--module-path /Library/Java/JavaVirtualMachines/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml,javafx.fxml.
- Save the configuration, then click the run button—your JavaFX app should launch without any extra command-line steps!
VS Code 配置方法
First, make sure you have the Java Extension Pack installed (it includes all the necessary tools for Java development in VS Code).
- Open your JavaFX project folder in VS Code.
- Create a new folder named
.vscodein your project root directory. Inside this folder, create two files:settings.jsonandlaunch.json. - Configure
settings.jsonwith these contents (update paths to match your JDK and JavaFX SDK locations):{ "java.home": "/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home", "java.project.referencedLibraries": [ "/Library/Java/JavaVirtualMachines/javafx-sdk-11.0.2/lib/*.jar" ] } - Configure
launch.json(replaceyour.full.main.class.namewith your actual main class's fully qualified name, likecom.schoolproject.HelloFx):{ "version": "0.2.0", "configurations": [ { "type": "java", "name": "Launch JavaFX App", "request": "launch", "mainClass": "your.full.main.class.name", "vmArgs": "--module-path /Library/Java/JavaVirtualMachines/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml" } ] } - Save both files. Go to the Run and Debug tab (click the bug/play icon in the left sidebar, or use
Ctrl+Shift+D), select the "Launch JavaFX App" configuration, and click the play button to run your app.
Quick Tip
If you ever update your JDK or JavaFX SDK version, just remember to update the paths in these configurations to match the new locations!
内容的提问来源于stack exchange,提问作者sietze




