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

huangapple go评论80阅读模式
英文:

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

问题

我用eclipse制作了我的第一个java/JavaFX应用程序,并导出了可运行的Jar文件。在我的计算机上,它可以使用以下命令正常运行:

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

但是当我尝试在另一台计算机上运行时,出现以下错误:

无法识别的选项:--module-path 错误:无法创建Java虚拟机。错误:发生了致命异常。程序将退出。

在我的计算机上,Java -version 命令显示:

java版本 "15" 2020-09-15

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

Java HotSpot(TM) 64-Bit Server VM(构建15+36-1562,混合模式,共享)

在用户的计算机上,我得到:

java版本 "1.8.0_201"

Java(TM) SE Runtime Environment(构建1.8.0_201-b09)

Java HotSpot(TM) 64-Bit Server VM(构建25.201-b09,混合模式)

我需要在用户的计算机上安装哪个最低版本的Java才能使这个工作正常?在eclipse中是否还需要进行其他操作才能使这在最终用户的计算机上正常工作?我应该使用另一个版本的Java来构建我的应用程序吗?我感到很困惑。

英文:

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.

答案1

得分: 1

正确的答案取决于上下文,但可能是java9或者java11。'java9',从直接回答'最低版本是什么'的意义上来说是正确的。'java11',实际上这是你应该安装的版本,因为在这个时候已经没有了java9。java9不是一个长期支持的版本。几乎没有人(甚至连Oracle,除非你支付相当高的费用)再对其进行支持。

Java8和Java11是唯一应该安装在最终用户计算机上的Java版本。如果你在使用模块,那么答案就是java11。

英文:

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.

答案2

得分: 1

你需要为每台要在其上运行应用程序的新计算机设置兼容的Java安装。一种简单的方法是使用 jlinkruntime 目录中构建一个与你的应用程序兼容的JRE:

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

你可以添加以下额外的 jlink 参数来减小映像大小: --strip-debug --no-man-pages --no-header-files --compress=1

然后,你应该能够在当前计算机上使用新的JRE运行时映像运行应用程序,其中包含了 JavaFX javafx.controls 模块及其所有依赖项:

myruntime\bin\java -version
=> 应确认:java version "15"

myruntime\bin\java javafx.application.Application
=> 应报告:Error: Main method not found in class javafx.application.Application
=> 这确认了 JavaFX 是 JRE 的一部分

myruntime\bin\java -jar ".\myProgram.jar"
=> 应该运行你的应用程序

然后,你可以将带有代码的 runtime 目录复制到其他计算机,并以与当前计算机相同的方式运行,只要保持相同的相对目录结构即可。

如果所有这些都有效,你可以尝试为运行时 JRE + 你的代码构建Windows MSI安装包,以便你可以为自己的应用程序使用标准的Windows安装程序。详情请参见 jpackage

英文:

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

huangapple
  • 本文由 发表于 2020年9月30日 09:08:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/64129599.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定