1

I am working on a project that uses Javafx, and my goal is to make a .exe file with Launch4J, because it will be used by other people.
For now, when I export the project in a runnable JAR, if I want to execute it, I have to write as an argument the path of the javafx folder and add the different modules :
java --module-path javafx-sdk-17.0.2\lib --add-modules javafx.controls,javafx.fxml -jar test13.05.jar
Is there a way to put the javafx folder in my projects lib folder, and add the arguments directely into the main function so I can execute the project without having to write the path and add the modules ?

A.CAL
  • 41
  • 6
  • You can make a desktop shortcut with all jvm arguments as command. Then you just have to click its shortcut – Giovanni Contreras May 20 '22 at 16:51
  • I could but I want to be able to send the jar via mail to other people, would it be transferred with the file? – A.CAL May 20 '22 at 16:56
  • Yes you can if you put all paths relative. I am using ubuntu. I can make an answer if you want – Giovanni Contreras May 20 '22 at 17:01
  • There are other aproach by adding libs in jar and editing its manifest. That will result on just one file – Giovanni Contreras May 20 '22 at 17:04
  • I think it would help me a lot if you did that. I am using windows and I launch the project from powershell. – A.CAL May 20 '22 at 17:09
  • i post it please don't tick as right answer because is not . it's just an idea I give you to solve your issue quickly . there are more elaborated approaches , but need gradle or maven . good luck ! – Giovanni Contreras May 20 '22 at 19:07
  • 1
    Instead of distributing a .jar file, you can distribute an [image tree](https://stackoverflow.com/questions/53453212/how-to-deploy-a-javafx-11-desktop-application-with-a-jre). – VGR May 20 '22 at 20:03
  • You might want to look at the info on packaging in the [JavaFX tag](https://stackoverflow.com/tags/javafx/info). – jewelsea May 20 '22 at 20:51
  • the idea of packing everything in one file is bad! once you use `launch4j`, set all the options for launching the application in it. when you create the exe file, don't pack everything in it but just create a native launcher (and of course, organize the directory of the application /bin, /lib, /runtime ...). the last step is to create an installer to distribute the entire application package as a single installation file. – mr mcwolf May 21 '22 at 05:11

2 Answers2

2

Fat jars are not recommended to distribute JavaFX application for various reasons. Instead use the official jpackage tool to package your application.

mipa
  • 10,369
  • 2
  • 16
  • 35
1

solution with a script (linux ubuntu version) run script

Adding jvm arguments as command in .sh script. every path must be relative in order to run it in other linux pc .Nescesary javafx jar are in libs folder

run_demo.sh

#! /bin/bash
java --module-path libs --add-modules javafx.controls -jar  demo-1.0-SNAPSHOT.jar  

This aproach can be implemented in other os with their proper scripts

Giovanni Contreras
  • 2,345
  • 1
  • 13
  • 22