简体   繁体   中英

What do I need to install on the end users computer to run my Java application made with eclipse

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM