安装e(fx)clipse后创建JavaFX项目出现import javafx无法解析错误求助
解决"The import javafx cannot be resolved"错误(JDK12 + e(fx)clipse3.5.0)
Hey there, I've dealt with this exact issue before—JDK 12 no longer includes JavaFX SDK by default (Oracle removed it starting from JDK 11), which is the root cause of your import error. Let's walk through the fix step by step:
Step 1: Download the matching JavaFX SDK
- Grab the JavaFX 12 SDK from the OpenJFX website (make sure the version matches your JDK 12 exactly, e.g., javafx-sdk-12.0.2)
- Extract the SDK to a local folder without spaces in the path, like
C:\javafx-sdk-12
Step 2: Add JavaFX SDK to your project's build path
- Right-click your JavaFX project in Eclipse → Build Path → Configure Build Path
- Switch to the Libraries tab, click Add Library → select JavaFX SDK → click Next
- Hit Directory and browse to the root folder of your extracted JavaFX SDK (the one containing
lib,bin, etc.), then click Finish - You should now see the JavaFX libraries listed under your project's build path
Step 3: Configure VM arguments for runtime
Even if imports work now, you'll hit a runtime error without this step:
- Right-click your project → Run As → Run Configurations
- Select the Java Application entry for your main class, switch to the Arguments tab
- In the VM arguments field, paste this (replace the path with your actual SDK path):
--module-path "C:\javafx-sdk-12\lib" --add-modules javafx.controls,javafx.fxml- Add extra modules like
javafx.weborjavafx.mediaif your project uses them
- Add extra modules like
Step 4: (Optional) Set global JavaFX SDK in Eclipse preferences
To avoid repeating this setup for future projects:
- Go to Window → Preferences → JavaFX
- Click Add to add your JavaFX SDK path, then set it as the default
Extra note for modular projects
If your project uses a module-info.java file, make sure to declare dependencies on JavaFX modules:
module your.project.name { requires javafx.controls; requires javafx.fxml; // Add other modules as needed opens your.project.package to javafx.fxml; }
内容的提问来源于stack exchange,提问作者rain1
相关产品推荐
相关产品推荐

