如何强制我的 Java 应用程序使用 Java JRE 1.6 而不是 1.7?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12650293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:42:21  来源:igfitidea点击:

How do I force my Java application to use Java JRE 1.6 instead of 1.7?

ftpjava

提问by Meeks

Possible Duplicate:
How to check JRE version prior to launch?

可能重复:
如何在启动前检查 JRE 版本?

Many people want to know how to force their program to use a minimum version of a jre, but I would like my program to only run using java 6 and not java 7 (aka maximum of jre 1.6). The reason being that my program needs to use FTP, and java 7 has the dreaded FTP bug.

许多人想知道如何强制他们的程序使用 jre 的最低版本,但我希望我的程序只能使用 java 6 而不是 java 7(也就是最大的 jre 1.6)运行。原因是我的程序需要使用 FTP,而 java 7 有可怕的 FTP 错误。

Is there a way to easily make my application run using 1.6 if the user has 1.7 installed?

如果用户安装了 1.7,有没有办法让我的应用程序使用 1.6 轻松运行?

Some of the options I have looked at are: launch4j

我看过的一些选项是:launch4j

I am not quite certain that it will solve my problem, other than perhaps bundling the entire jre with my program. Which I don't think is the most ideal solution.

我不太确定它会解决我的问题,除了可能将整个 jre 与我的程序捆绑在一起。我认为这不是最理想的解决方案。

Can someone help guide me even down the theoretical path as to how this is generally solved/handled?

有人可以帮助指导我甚至在理论上如何解决/处理这个问题吗?

回答by Esko

As suggested in this somewhat related question/answer, use System.getProperty("java.version")to see what version of Java is being used to run the application. With this you can make the application prompt the user that he should use an older JRE.

正如在这个有些相关的问题/答案中所建议的那样,使用System.getProperty("java.version")来查看用于运行应用程序的 Java 版本。有了这个,您可以让应用程序提示用户他应该使用较旧的 JRE。

As for running the application without path based JRE detection, the main problem is that you can't be certain where on the user's system the correct JRE is installed. On Windows there's two default possibilities, on *nix it might be anywhere.

至于在没有基于路径的 JRE 检测的情况下运行应用程序,主要问题是您无法确定在用户系统上的哪个位置安装了正确的 JRE。在 Windows 上有两种默认可能性,在 *nix 上它可能在任何地方。

If I were you, I'd try to find a custom FTP library that gets around the bug you mentioned to get the maximum security and optimization benefits of the newer versions of Java instead of forcing the user to stay in the past.

如果我是你,我会尝试找到一个自定义 FTP 库来解决你提到的错误,以获得新版本 Java 的最大安全性和优化优势,而不是强迫用户留在过去。