5

I have a javafx application and I want to compress it and its module dependencies (javaFX) into a single jar file via windows command prompt, so that you can run it via double click anywhere without needing the javafx sdk.

The javaFX modules I'm using are controls & web.

I've searched extensively for information on how to do this. All I've found however is stuff on running the jar with javaFX modules. However, this doesn't fit the single jar file requirement, as you need to have downloaded the javaFX sdk separately.

Kein
  • 348
  • 1
  • 3
  • 15
  • What is the version of javafx you are using ? – omernaci Sep 02 '19 at 06:20
  • javafx sdk 12.0.1 – Kein Sep 02 '19 at 06:22
  • 1
    Did you search for 'Uber jar' and 'gradle all in one jar'? – mojtab23 Sep 02 '19 at 06:22
  • 1
    Have you checked any of these threads: [link](https://stackoverflow.com/questions/54063041/package-a-non-modular-javafx-application/54065502#54065502), [link](https://stackoverflow.com/questions/55300695/jdk11-javafx-how-do-i-make-a-fat-jar-without-build-depdency-management/55303408#55303408) or [link](https://stackoverflow.com/questions/52653836/maven-shade-javafx-runtime-components-are-missing/52654791#52654791)? – José Pereda Sep 02 '19 at 10:26
  • You can certainly create a fat JAR, even a cross-platform fat JAR, as @José shows in one of his links. However, this only works with the classpath. The problem with a fat JAR is you can only have one module per JAR file. This means the JavaFX modules cease to exist once you extract them into your own JAR file; either the JavaFX classes are now part of _your_ module or there is no module. On top of that, there is no support for executable modular JARs. When you double-click a JAR file it gets launched via `java[w] -jar ` which uses the classpath, not modulepath. – Slaw Sep 02 '19 at 11:40
  • In other words, to use the modulepath yet still only ship one JAR file you'll have to do at least two things: (1) Embed the actual JavaFX JAR files in your own JAR file instead of extract them; this requires you to write some infrastructure code because Java cannot read a JAR-in-a-JAR by default. (2) Figure out a way to launch the application on the modulepath; this may require a custom script or maybe you could have a separate (still embedded) main-JAR that manually builds the `ModuleLayer`s of your application. – Slaw Sep 02 '19 at 11:44
  • Alright, so I think I've managed to do it with the maven shade plugin by creating an uber jar. However, when I run the jar I get a null pointer exception when webEngine.load() runs, despite including javafx-web in pom.xml. – Kein Sep 02 '19 at 19:34

0 Answers0