nus-cs2113-AY1920S2 / forum

4 stars 0 forks source link

Packaging a JavaFX application in a .jar is possible only with Java 8. #34

Closed wangqinNick closed 4 years ago

wangqinNick commented 4 years ago

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

issue: IDEA-200721 https://youtrack.jetbrains.com/issue/IDEA-200721?_ga=2.226103452.787797951.1581843904-766222336.1581314726

Is it possible to build a jar file if I change the SDK to Java 8 ?

damithc commented 4 years ago

Creating jar using Java 8 is no good because the user will be using Java 11.

If you use JavaFX in Java 11, you need to create a fat jar that includes the required JavaFX libraries. For that, it's best to use a build tool such as Gradle. Both are beyond the requirements of the module, but we wont stop you if you want to try. Duke repo comes with a JavaFX and Gradle tutorial although they were not used in the module.

wangqinNick commented 4 years ago

The only working solution I found so far is build a shadowJar with shadow plug-in using Gradle. It works perfectly. However, other methods I tried like, a normal fat jar with dependencies does not work. Maybe it is because I am using external library?

damithc commented 4 years ago

The only working solution I found so far is build a shadowJar with shadow plug-in using Gradle. It works perfectly.

That's the recommended approach.