intellij-ideajavafxintellij-14intellij-13intellij-15

How to create an empty JavaFX project in IntelliJ


Every time I create a new JavaFX project in IntelliJ it loads a simple HelloWorld project in it. How can I make it empty instead (without the need to delete those .java files every time)? Also how can I choose to create the project without a building system (as you can see in the picture, I'm always forced to create the project with Maven or Gradle)

enter image description here


Solution

  • enter link description hereWhen creating the new project, choose "Java" instead of "JavaFX".

    A JavaFX application is just a Java application, so if you don't want the additional things which IntelliJ is doing when you choose to create a JavaFX project (e.g. supplying example code and associating with a build system like Maven or Gradle), you can just choose a basic Java application project from the wizard and it won't do those other things.

    See the section in openjfx.io documentation titled "JavaFX and IntelliJ IDEA" for other steps you need to take:

    1. Set the project JDK

      • File -> Project Structure -> Project
    2. Create a JavaFX library in Idea

      • File -> Project Structure -> Libraries
      • Point to the lib folder of the JavaFX SDK.
    3. Add VM options for the module path

      • Run -> Edit Configurations...

        --module-path /path/to/javafx-sdk-15.0.1/lib --add-modules javafx.controls,javafx.fxml
        

      For windows use quotes around the path and \ rather than /.

    4. Run the project

      • Run -> Run...

    You might also need to take the actions identified in the accepted answer to:

    But that answer was written a while back and setting the resource copy configuration to include JavaFX fxml and css files might not be needed anymore.

    Now, you might think that is annoying amount of things to do, and I might agree with you.

    Update Aug 2023

    Instructions above are advice for creating an empty project. For most people, I think creating a project with example code is a better option. Then you start with a project you know will work. To do that I recommend using the Idea wizard to create a new JavaFX project:

    It is easy enough then to manually remove (or add to) parts of the sample project to get the setup you want for your project.