How to create a JavaFX Maven project in IntelliJ IDEA?

前端 未结 5 1877
花落未央
花落未央 2021-02-04 01:58

How can I open a JavaFX Maven project from scratch in IntelliJ IDEA? As there is no difference between a Java project and a JavaFx project, I want to open a dedicated JavaFX pro

5条回答
  •  时光取名叫无心
    2021-02-04 02:11

    It takes me a couple of hours to find the right solution. Many thanks to this video and the author: https://www.youtube.com/watch?v=qn2tbftFjno

    So, following the above video, I would like to recommend:

    1. Download JavaFX SDK from https://gluonhq.com/products/javafx/
    2. Extract the zip file
    3. From the starting page of Intellij IDEA, select Configure/Structure for New Projects
    4. Select Platform Settings/Global Libraries
    5. Select the plus ("+") button/Java
    6. Find the "lib" folder inside your extracted zip file and select all of ".jar" files (except "src.zip"), and then OK
    7. Set a new name for the library, let's say "javafx-whatever-version", then Apply/OK
    8. Create a JavaFX project as normally.
    9. Select File/Project Structure...
    10. From Project Settings/Project, remember to select the suitable Project SDK and Project language level
    11. From Platform Settings/Global Libraries, right click on the library "javafx-whatever-version" (which you have already added), choose Add to modules.../OK
    12. Switch to Project Settings/Modules, choose Apply/OK
    13. Back to your project manager, right click on "src"/New/module-info.java
    14. Add new lines to the body of module-info.java:
    requires javafx.fxml; 
    requires javafx.controls; 
    opens sample;
    
    1. Run the project and enjoy!

提交回复
热议问题