Tenardie
Tenardie

Reputation: 57

How to build a executable JavaFX 11 application

Problem

I can't create "JavaFX Application" Artifact on IntelliJ IDEA, It gives " 'javafx:deploy' is not implemented in this SDK." error.

I don't want to use Maven/Gradle because; With Maven: I can't use my local jar library, I tried including as a lib, using Jitpack, Adding something in POM but none of them worked. With Gradle: I don't understand Gradle, but I think it has same issue with maven (local libraries). So I need a solution without Maven/Gradle.

Details

I tried creating "JAR Application" Artifact and built it but it doesn't run with double click or console command. I am sure I installed and configured JavaFX & jmods correctly.

What I want

Build an JavaFX executable, which runs without needing console command.

System Properties

Upvotes: 1

Views: 1419

Answers (2)

mipa
mipa

Reputation: 10650

Just go for jpackage. Here is the link to the documentation. https://docs.oracle.com/en/java/javase/16/jpackage/packaging-overview.html#GUID-C1027043-587D-418D-8188-EF8F44A4C06A

Upvotes: 2

Nephty
Nephty

Reputation: 150

Not a solution without Gradle/Maven but I highly recommend you try using Gradle. Create a new Gradle Project (very easy if you use IntelliJ), and you only need to add dependencies in the build.gradle file. Example of what I use to make a Gradle Project using JavaFX :

plugins {
    // Apply the application plugin to add support for building a CLI application in java.
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.9'
}

repositories {
    mavenCentral()
}

dependencies {
    // This dependency is used by the application
    implementation 'com.google.guava:guava:29.0-jre'
    implementation 'com.googlecode.json-simple:json-simple:1.1.1'

    // Use JUnit test framework
    testCompile('org.junit.jupiter:junit-jupiter-api:5.3.1')
    testCompile('org.junit.jupiter:junit-jupiter-engine:5.3.1')

}

run {
    standardInput = System.in
}

application {
    mainClass = "com.Nephty.main"
}

javafx {
    version = "15.0.1"
    modules = [ 'javafx.controls' , 'javafx.fxml' , 'javafx.media' ]
}

Two important points : repositories, application and javafx.

In repositories, you specify the repository from which you want to download the librairies, so you don't have to keep them on your local machine. This helps sharing your program, as another user won't have to download and setup JavaFX himself (this can be impossible for a non tech-savy).

In JavaFX, you specify the modules you want to use and the version.

In application, you specify your main class which will be ran.

Then, you can do a console command : graldew.bat run (with cwd as your project directory) or use the easily accessible task in IntelliJ. After that, you can create a shortcut that will automatically run the console command without needing you to open the console and type everything out. If you are the only who is going to use your application, this is the same as having an executable (if we only care about using the program).

There is an application that helps building executable files for java application. This video explains it.

Hopefully you can find what you're looking for here. If not, don't mind replying so we can try to figure something out.

Upvotes: 1

Related Questions