如何在JRE 1.8上运行Java 11和JavaFX 11应用程序。

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

How to run java11 and jfx11 application on jre1.8

问题

我是一名计算机专业的学生,在一家公司的实习期间,我开发了一个小的Java软件,使用了JavaFX、Maven和apache.poi。

信息:该应用在Intellij上运行并且构建完美,我的问题涉及我在项目完成后生成的 *.jar 文件。

起初我使用了JDK 14和JFX 14,然而在执行(java –jar xx.jar)时,我遇到了一个错误,指出我在JAVA 58(JAVA 14)中编译程序,而我正在使用JRE 52(JAVA 8)。

因此,我修改了项目,改为使用JDK 11和JFX 11进行编译,现在我遇到了相同的错误,告诉我我正在JAVA 55(JAVA 11)中编译程序,而我正在使用JRE 52(JAVA 8)。

错误是因为我的PC默认使用jre1.8.0_251。

所以,我尝试以这种方式启动程序:“path_to_jdk11 \ bin \ java.exe” -jar xxx.jar,它可以正常工作。

这就是我的问题:

大多数用户使用Oracle网站上提供的JAVA版本,即jre1.8.0_251,这是可用的最新版本。然而,我的程序需要Java 11,在企业PC上无法部署,我想象。

我尝试将项目转换为Java 8,但在Maven和module.info.java方面出现了错误。

您是否有关于部署 *.jar 文件或将其部署为 .exe 文件的建议,以便可以在安装了jre1.8.0_251的用户上运行?

谨上

英文:

I am a computer student and I had during my internship in a company, develop a small java software using JavaFX, maven, and apache.poi.

Info: The application works on Intellij and builds perfectly, my problem concerns the *.jar that I generate once the project is finished.

I first used JDK 14 and JFX14, however at the time of the execution (java –jar xx.jar) I had an error saying that I was compiling the program in JAVA 58 (JAVA 14) and that I was using JRE 52 (JAVA 8).

So I modified the project to compile with JDK 11 and JFX 11, and I now have the same error telling me that I am compiling the program in JAVA 55 (JAVA 11) and that I was using JRE 52 (JAVA 8).

The error comes from the fact that my PC uses jre1.8.0_251 by default.

So I tried to launch the program in this way "path_to_jdk11 \ bin \ java.exe" -jar xxx.jar and it works.

So that's my problem:

The majority of users use the version of JAVA offered on the Oracle site, i.e. jre1.8.0_251 which is the latest version available. Outside my program requires Java 11, which is not deploying on corporate PCs, I imagine.
I tried to port my project to java 8 but I have errors with Maven and the module.info.java.

Do you have a tip for deploying the *.jar or deploying it in .exe so that it can run with a user who has jre1.8.0_251?

Respectfully

答案1

得分: 0

不要尝试构建一个臃肿的JAR文件。它在现代Java中不起作用。而是要构建一个真正的安装程序。这在JDK 14+中可以很容易地实现。只需按照这个教程 https://github.com/dlemmermann/JPackageScriptFX 进行操作,该教程涵盖了你所需的一切。其中使用了来自JDK 14的jpackage以及一些其他工具,还适用于非模块化项目。当你安装JDK 14时,确保设置好JAVA_HOME和PATH,以便所有工具可以找到正确版本的Java来进行构建。

英文:

Don't try to build a fat jar. It won't work with modern Java. Instead build a real installer. This can be done easily with JDK 14+. Just follow this tutorial https://github.com/dlemmermann/JPackageScriptFX which covers everything you need. This uses jpackage from JDK 14 and some other tools from it and also works with non-modularized projects. When you install JDK 14 just make sure you set JAVA_HOME and your PATH correctly so that all the tools find the correct version of Java for building.

huangapple
  • 本文由 发表于 2020年5月5日 17:48:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/61610248.html
匿名

发表评论

匿名网友

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

确定