Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build and deploy javafx application using java11

I followed the steps in https://blog.jetbrains.com/idea/2013/03/packaging-javafx-2-applications-in-intellij-idea-121/

but when I try to build artifacts the as in the last step I get this error

enter image description here

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

enter image description here

I know JavaFX has been removed from java11 my question is what should I do to build a .jar or .exe

here is a hello world app for quick testing.

like image 612
humazed Avatar asked Nov 23 '18 16:11

humazed


3 Answers

Using the JavafX JAR export option doesn't work anymore in Intelij. You can export it as a regular jar with "Jar-From module with dependencies". This will export a valid Jar, but in order to run it, you need to add your javaFx path and modules to your command.

After you have the jar, the run command should look something like this:

java --module-path PATH_TO_YOUR_JAVAFX_LIB_FOLDER --add-modules javafx.controls,javafx.fxml,javafx.graphics,javafx.web -jar yourJar.jar

I made a youtube tutorial with this: https://youtu.be/HGHu-SzL-5E

like image 109
Barosanu240 Avatar answered Sep 25 '22 05:09

Barosanu240


Unfortunately, you won't be able to build your jar using JFX11 this way, as apparently the packager was removed from the JFX SDK. There is hope it will be implemented in a future release (maybe 12). Read here for more details:

https://youtrack.jetbrains.com/issue/IDEA-200721 containing the following 2 links:

https://bugs.openjdk.java.net/browse/JDK-8212780

https://openjdk.java.net/jeps/343

As a temporary solution, you might simply use/downgrade to version 10 which still includes the needed packager.

like image 36
Ioannis Panteleakis Avatar answered Sep 26 '22 05:09

Ioannis Panteleakis


The following method works for me with OpenJDK 11 and OpenJFX 11 on Windows and Ubuntu using IntelliJ and successfully creates a jar that can be run with just java -jar filename.jar without JavaFX installed on the target machine. Keep in mind that the JavaFX jars are platform dependent. So the Windows jar needs to be compiled on Windows and the Linux jar compiled on Linux.

My main method extends application...

public class Main extends Application {

So, first make a new Java class something like Start.java - this links to the original Main method.

public class Start {
    public static void main(String[] args){
        Main.main(args);
    }
}

Then you make the .jar file;

File > Project Structure > Artifacts

Click + > Choose JAR > From Modules with dependencies

For the Main class choose the Start.java > click Ok

The javafx jars should be extracted automatically (if they're not add them manually)

Click Apply and Ok

Build > Build Artifacts > Build

The file created should run fine with just java -jar filename.jar even on machines without JavaFX installed.

like image 36
Harley Avatar answered Sep 24 '22 05:09

Harley