0

I made my first java/JavaFX application using eclipse and exported the Runnable Jar file. On my computer it runs just fine using the following command:

java --module-path ".\lib" --add-modules=javafx.controls -jar ".\myProgram.jar"

but when I tried to run in on another computer I get the following error:

Unrecognized option: --module-path Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.

On my computer Java -version gives me:

java version "15" 2020-09-15

Java(TM) SE Runtime Environment (build 15+36-1562)

Java HotSpot(TM) 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)

On the user's computer I get:

java version "1.8.0_201"

Java(TM) SE Runtime Environment (build 1.8.0_201-b09)

Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

What is the minimal version of Java I need to install one the users computers to make this work. Is there something else I need to do in eclipse to make this work on the end users computer. Should I use another version of Java to build my application ? I'm lost.

JobouJP
  • 33
  • 6
  • Why not compile for a earlier version e.g. version 8? – Scary Wombat Sep 30 '20 at 01:17
  • If you use the jlink command that comes with every JDK, you won’t have to install any Java on a user’s computer. See https://stackoverflow.com/questions/53453212/how-to-deploy-a-javafx-11-desktop-application-with-a-jre. – VGR Sep 30 '20 at 02:12
  • VGR, I tried to change my project to a modular system so I can do this , but I ran into several conflict issues with the external JAR's I was using. So I'm stuck on that side for now. – JobouJP Sep 30 '20 at 21:08

2 Answers2

1

The right answer depends on context, but it is either java9 or java11. 'java9', in the sense that this is the direct answer to 'what is the minimal version'. 'java11' in, that is actually what you should install, as there is no java9 at this point. java9 was not a long-term support version. Pretty much nobody (not even oracle, unless you pay rather premium prices) supports it anymore.

Java8 and Java11 are the only java's you should ever be installing on end-user computers. If you're using modules, then java11 is the answer.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
  • Well, as this application was developed on Java 15 it is possible that this was also compiled for Java 15 and thus the jar file won't run in a Java 11 environment. It may even be possible that certain new features have been used which are also not available on Java 11. So, without knowing this it is not possible to give a definitive answer. – mipa Sep 30 '20 at 08:36
1

You will need to setup a compatible Java installation for each new computer you want to run your application on. An easy way to do that is use jlink to build a compatible JRE in runtime directory for your application:

 jlink --module-path ".\lib" --add-modules=javafx.controls --output myruntime

You could add these extra jlink arguments to reduce the image size: --strip-debug --no-man-pages --no-header-files --compress=1

Then you should be able to run your application on current machine with the new JRE runtime image which now contains JavaFX javafx.controls module and all its dependencies:

myruntime\bin\java -version
=> should confirm: java version "15"

myruntime\bin\java javafx.application.Application
=> should report: Error: Main method not found in class javafx.application.Application
=> This confirms JavaFX is part of the JRE

myruntime\bin\java -jar ".\myProgram.jar"
=> should run your application

Then you can copy runtime directory with your code to other machines and run in same manner as current machine as long as you have kept the same relative directory structure.

If all that works, you could try building Windows MSI installation package for runtime JRE + your code so that you can use standard Windows installer for your own apps. See jpackage

DuncG
  • 12,137
  • 2
  • 21
  • 33