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

11,429

Solution 1

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

Solution 2

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.

Share:
11,429

Related videos on Youtube

Mr. Nielzom
Author by

Mr. Nielzom

Updated on June 04, 2022

Comments

  • Mr. Nielzom
    Mr. Nielzom almost 2 years

    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.

  • Dan A.S.
    Dan A.S. over 3 years
    Here is an excellent video explaining the second option: youtube.com/watch?v=HGHu-SzL-5E&ab_channel=AlexHorea