Run HelloWorld using Maven

If you want to develop JavaFX applications using Maven, you don't have to download the JavaFX SDK. Just specify the modules and the versions you want in the pom.xml, and the build system will download the required modules, including the native libraries for your platform.

Here is a pom.xml file which shows how to achieve this, included in this sample.

Alternatively, we have created JavaFX Maven Archetypes to quickly create Maven projects. A simple JavaFX project can be created by executing the following command:

mvn archetype:generate \
        -DarchetypeGroupId=org.openjfx \
        -DarchetypeArtifactId=javafx-archetype-simple \
        -DarchetypeVersion=0.0.3 \
        -DgroupId=org.openjfx \
        -DartifactId=sample \
        -Dversion=1.0.0 \

The pom uses the JavaFX Maven plugin:


Add the maven dependencies:


Important: Note that transitive dependencies are automatically resolved (for instance, there is no need to add a dependency for the module, since it is transitively resolved by the javafx.controls module). But if your application is using FXML, you will need to add a dependency for the javafx.fxml module as well.

Finally, run the application (e.g. based on the from the referred sample):

mvn clean javafx:run
Note: Make sure to set the JAVA_HOME environment variable to the correct JDK location.