1

I built an app with javaFX using Eclipse, and I have used following libraries:

  • javaFx Sdk
  • barCode4j
  • mysql connector j

So how can I create a runnable jar file that runs with a double click? I don't want to run it every time I add a module because the app is for a simple user.

I had created a demo app and the command maven -> runs perfectly fine. But in my project

mvn clean install javafx:run;

when I am exporting it the and trying following

java -jar myApp.jar

throws an exception

"require java fx environment component "

so how can I slove it ?

Vaibhav Sharma
  • 1,573
  • 2
  • 19
  • 35
  • 3
    Do you really want a "simple user" to download and install Java to run your app? If not, then use jlink to create a zip with your runtime or jpackage to create package with a native installer (or if your app or dependent libraries aren't fully modular). See [packaging info in the JavaFX tag](https://stackoverflow.com/tags/javafx/info) for more info, and, yes, it will required you do additional work which likely won't be easy for you. – jewelsea May 15 '23 at 23:13
  • The [`javafx-maven-plugin`](https://github.com/openjfx/javafx-maven-plugin) helps with the `jlink` [options](https://github.com/openjfx/javafx-maven-plugin#javafxjlink-options). – trashgod May 16 '23 at 15:39
  • jlink is almost not usable for modular applications... The solution with Maven is to pack the application into a single jar file with all dependencies (you need to use Maven plugin for this). The next thing is, that you cannot start the application from the class that extends "Application". You need to create a class that will call main method of the class which extends the Application. – Ján Яabčan May 16 '23 at 22:05
  • @JánЯabčan jlink is definitely usable for modular applications and, in situations where it can be used, is good. Where it does not work is for non-modular applications or applications with dependencies on automatic modules. Unfortunately, many dependent libraries are not fully modularized, so must be placed on the classpath or loaded as automatic modules (which causes issues when using jlink). I guess that is what you are referring to. As far as I could tell, the MySQL connector library used by the asker, is non-modular, so jlink probably won't be the solution for the asker. – jewelsea May 17 '23 at 23:13
  • jpackage can be used, but in my experience on Mac appears to require a paid signing certificate from Apple to complete the packaging, so may not be appropriate if Mac is a target, other platforms are probably OK. The single jar installation is not a supported configuration and many people have issues trying to get it to work, it is explained in [this answer](https://stackoverflow.com/questions/52653836/maven-shade-javafx-runtime-components-are-missing/52654791#52654791). – jewelsea May 17 '23 at 23:15

0 Answers0