检查Java版本是否大于Java中的某个迭代版本

检查Java版本是否大于Java中的某个迭代版本

本文介绍了检查Java版本是否大于Java中的某个迭代版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望检查用户的Java版本是否至少为1.8.0_171.我的意思是特定的迭代或更高版本(例如1.8.0_151)将无法正常工作.

I wish to check if a user's Java version is at least 1.8.0_171. I mean that specific iteration or higher, meaning 1.8.0_151, for instance, would not work.

我原本打算使用org.apache.commons.lang3.SystemUtils的isJavaVersionAtLeast(JavaVersion requiredVersion)方法,但似乎无法指定迭代编号.

I planned to originally use org.apache.commons.lang3.SystemUtils' isJavaVersionAtLeast(JavaVersion requiredVersion) method, but it seems that you cannot specify the iteration number.

基于此以及Java不断变化的表示Java版本号的方式(例如1.8到9),什么是在Java程序中检查用户Java版本的最佳方法?

Based on this and Java's changing way of representing version numbers in Java (e.g. 1.8 then 9), what is the best way to check the Java version of the user in the Java program?

此问题被标记为此问题的副本;但是,我认为这是不同的,因为它要求更改Java版本的显示格式,因此询问如何将Java版本与特定版本进行比较.

This was marked as a duplicate of this question; however, I think it is different in that it asks how to compare the java version with a certain version given the changes in format of how the java version is shown.

推荐答案

即使更改了版本,我仍然认为解决方案仍然像使用以下布尔表达式一样简单:

Even with the versioning change, I think the solution is still as simple as using the following boolean expression:

"1.8.0_171".compareTo(System.getProperty("java.version")) <= 0

如果用户的java.version属性小于1.8.0_171,则以上表达式返回false,反之亦然.这也适用于使用"9""10"代替java.version属性.

If the user's java.version property is any less than 1.8.0_171, then the above expression returns false, and vice versa. This works for using "9" or "10" in place of the java.version property as well.

这篇关于检查Java版本是否大于Java中的某个迭代版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 16:56