Creating the First JavaFX Project in IntelliJ IDE

After launching the executable file, the IntelliJ Welcome screen opens. Click on New Project. The following project configuration screen will appear:


Screenshot 2026-01-23 115515


Select JavaFX in the options on the left. When creating a project using the JavaFX generator, IntelliJ automatically prepares the initial structure for a JavaFX application, including the main class and launch configuration. JavaFX libraries are added automatically, so manual dependency configuration is not required at this stage.

  • Use the default folder for your selected workspace.
  • During configuration, select the Project SDK, preferably using the locally installed JDK. Set the language to Java and the build system to Maven.
  • Group ID: identifies the group the project belongs to, typically based on the organization’s fully qualified domain name, e.g., bg.tu.varna.sit.ps.
  • Artifact ID: unique base name for the main artifact generated by the project. The main artifact is usually a JAR file. Other project artifacts use this name to form their names.

After selecting the options, click Next, leave the next window unchanged, and click Create. Wait for the project to load.

Configuration

Since projects created with the JavaFX generator use a modular structure by default, the project includes a module-info.java file describing the JavaFX modules used. In the following steps, the structure will be changed from modular to monolithic to simplify learning and focus on core language and technology concepts.

  • Delete the module-info.java file: Right-click on the file → Delete.
  • Edit the configuration in pom.xml.

Once module-info.java is deleted, the project no longer uses the module system. To run a JavaFX application in a monolithic structure, a few changes in pom.xml are required.

Introduction to XML

1. Open pom.xml - located in the project root directory.

Screenshot 2026-01-25 235807

  • Locate the <build><plugins><plugin> tags for javafx-maven-plugin.

Current configuration:

<plugin>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>0.0.8</version>
    <executions>
        <execution>
            <id>default-cli</id>
            <configuration>
                <mainClass>bg.tu_varna.sit.ps.demo1/bg.tu_varna.sit.ps.demo1.HelloApplication</mainClass>
                <launcher>app</launcher>
                <jlinkZipName>app</jlinkZipName>
                <jlinkImageName>app</jlinkImageName>
                <noManPages>true</noManPages>
                <stripDebug>true</stripDebug>
                <noHeaderFiles>true</noHeaderFiles>
            </configuration>
        </execution>
    </executions>
</plugin>

2. Edit the tags

The current structure has duplicate package references (bg.tu_varna.sit.ps.demo1/bg.tu_varna.sit.ps.demo1.HelloApplication) specific to modular projects.

2.1. Change <mainClass> to the full class name with package:

<mainClass>bg.tu_varna.sit.ps.myfirstjavafxproject.HelloApplication</mainClass>

2.2. Comment out or delete unnecessary tags:

The <launcher>, <jlinkZipName>, <jlinkImageName>, <noManPages>, <stripDebug>, <noHeaderFiles> tags are specific to modular projects and jlink. For a monolithic project, they are unnecessary and can be commented out:

<!--
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
-->

2.3. Add <options> tag

This adds JVM arguments to give the project access to Java packages otherwise blocked by the module system:

<options>
    <option>--add-opens</option>
    <option>java.base/java.lang=ALL-UNNAMED</option>
</options>

This tells the JVM to open the java.lang package to all classes in the monolithic project, ensuring the application runs correctly without module-info.java.

3. Create Package and Main Classes

Once the project is monolithic and pom.xml is configured, create the Java structure and main classes for the JavaFX application.

3.1. Create a package

  • In the Project panel, navigate to src/main/java.
  • Right-click → New → Package.
  • Enter the package name:
bg.tu_varna.sit.ps.lab1

3.2. Create the main class HelloApplication

  • Right-click on the lab1 package → New → Java Class.
  • Class name: HelloApplication.

This class contains the code for the JavaFX interface. The start(Stage stage) method creates the window and controls.

3.3. Similarly, create the Launcher class

This class safely starts the JavaFX application. It contains main() to launch HelloApplication.

4. Create the First Program

Open the section for creating the first JavaFX program.


This site uses Just the Docs, a documentation theme for Jekyll.