Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 976
Mr. Nielzom Avatar asked Feb 21 '19 12:02

Mr. Nielzom


People also ask

What is FX deploy?

<fx:deploy> Used to assemble the application package for redistribution. By default, the deploy task will generate the base application package, but it can also generate self-contained application packages if requested. See also Section 5.7, "Run the Deploy Task or Command."


1 Answers

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

like image 125
AM429 Avatar answered Oct 14 '22 21:10

AM429