JavaFX can't build artifact - fx:deploy is not available in this JDK
Asked Answered
K

2

19

I have a JavaFX project that I would like to build as a Jar-file. However, when I attempt to do so, I get an error.

Error:Java FX Packager: Can't build artifact - fx:deploy is not available in this JDK

I found a similar problem on here from last year, but it seemed like they concluded nothing.

Krispin answered 21/2, 2019 at 12:12 Comment(1)
First, I downloaded the javaFx sdk from gluonhq.com/products/javafx, then I created a bat file and I included something like this: java --module-path PATH_TO_JAVAFX_SDK --add-modules=javafx.controls,javafx.fxml -jar PATH_TO_YOUR_JAR_FILED
G
15

This happens because either you have many JDKs installed and compiling by another and running by another or you are using the Javafx Application jar feature when creating artifacts in Intellij which is unfortunately broken. Before proceeding with the below steps make sure that you are compiling with and running with the same JDK version. Here is you fix it:

1 - Create a Launcher class:

The Launcher class is going to call the main JavaFx class from which your appliaction runs. Choosing to make the Jar directly through the Main class is going to error out giving the following error:

    Error: Could not find or load main class Main
    Caused by: java.lang.ClassNotFoundException: Main 

Your Launcher class should look something like this:

    public class Launcher {
        public static void main(String[] args) {
            MainGUI.main(args);
        }
    }

2 - On to building the Jar

  1. You probably still have a META-INF folder from the previous build so delete it.

  2. Build the project as a JAR:
    File->Project Structure -> Artifacts -> "+" -> JAR-> from modules with dependancies..

  3. Choose the Launcher class for you main and check "copy to the output directory and link via Manifest" and Press Ok

  4. Press Apply then OK.

  5. go to Build -> Build artifacts-> Rebuild

Goldshell answered 22/5, 2020 at 9:14 Comment(5)
Here is an excellent video explaining the second option: youtube.com/watch?v=HGHu-SzL-5E&ab_channel=AlexHoreaAlvis
I know I'm reviving an old topic (bad practice) but I just wanted to say a huge "Thank you!" because you saved me from pretty much wasting my work on a seemingly unpackage-able program.Bollen
It work! open without adding the modules and no error! thanksIphigeniah
Нет это не работает.Ratepayer
This YouTube Video was helpful for me: "JavaFX create executable jar in intellij 2023" youtube.com/watch?v=kQaE2HlFeWYCrier
T
1

In the JetBrains website I found a good article about, Package JavaFX applications which was really helpful. In the #troubleshoot section it says that,

Error:Java FX Packager: Can't build artifact – fx:deploy is not available in this JDK

The fx:deploy task was a part of the Ant plugin that was formerly distributed in ant-javafx.jar as a part of Java Packager. The Ant plugin is not included in jpackage in the current JDK versions.

If you're using a JDK build of version 9 and later, use third-party solutions for packaging. For example, refer to section Runtime images in the JavaFX official documentation.

Total answered 27/8, 2020 at 17:40 Comment(4)
This is a good summary. Additionally, if somebody is interested in packaging a Java (or JavaFX) application as a native application (e.g. an Windows exe, Linux rpm or deb package, or OS X dmg installed app), then consider using the jpackage utility implemented as an incubating feature in JDK 14+. For certain applications, this may provide a better requirements fit than the current options documented for JavaFX runtime images.Trypsin
@Trypsin thanks for mentioning about jpackage. Could you please help me figuring out this; I was trying to create an native executable for a JavaFX modular Maven project. With using javafx-maven-plugin I could create a runtime image with a launcher script & then by packaging it with jpackage, I got an bundled exe setup which works fine. But, it installs that launcher script. But what I need is to install running exe file. Any suggestion how to do it?Total
Ask a new question Tharindu. By doing so, multiple people may answer, you will have a better chance of finding someone with the appropriate knowledge to create a good answer for you and there will be a record which somebody can search to get an answer to a similar question.Trypsin
Kind of lame that what is supposed to be an IDE cannot even create a final output of a project. I mean, if it only works for Java 8 and below, that is useless in most cases. I do not understand why IntelliJ did not include a solution (whether their own or a third-party one) for Java 9+. Unless JavaFX is dying or something and IntelliJ practically gave up on it.Vizier

© 2022 - 2024 — McMap. All rights reserved.