Pradeep Kundarapu
Pradeep Kundarapu
Java developer, blogger and tech enthusiast.

Create simple window using JavaFX 11 and Maven

Create simple window using JavaFX 11 and Maven

JavaFX modules are no more part of OpenJDK. From version 11 JavaFX modules are separated from Java SDK and it’s a major version released after 8. JavaFX have its own website now In this article we will go through the process of creating and running simple JavaFX window using Maven. JavaFX 11 runtime is available in maven repository so we will use it with maven.

To make it simple I will use a terminal and a text editor to create this simple JavaFX window.


  • Java 11 (JavaFX 11 needs minimum Java 11 SDK to run)
  • Maven

Create Maven Project

In the terminal execute below command to generate an empty maven project.

mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=org.hello.fx -DartifactId=hello-fx

This command will generate a maven project with org.hello.fx package. Update pom.xml with below content.

<project xmlns="" xmlns:xsi=""
                                 <!--  or 11  -->

We need org.openjfx dependency, this dependency is the runtime environment for JavaFX so I added it and also we need below two plugins;

  • maven-compiler-plugin: To compile the project
  • exec-maven-plugin: I provided org.hello.fx.HelloFX as main class in the configuration. I will create this class in the next section, this class will initialize and run’s JavaFX class.

Create JavaFX class

Create a new class in hello-fx/src/main/java/org/hello/fx/

package org.hello.fx;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class HelloFX extends Application {
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(event -> System.out.println("Hello World!"));

        StackPane root = new StackPane();

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");

    public static void main(String[] args) {

This class opens a simple window with ‘Say Hello World’ button in center. Clicking on this button will print “Hello World!” in the console.

Run Application

Execute below command in the terminal to compile and run HelloFX class.

mvn compile exec:java

Maven will compile and run’s HelloFX class. New window will open with the button in center. Click on this button to see ‘Hello World!’ in the console.


We created and executed a simple JavaFX 11 window. You can import this project to any Java IDE.

comments powered by Disqus