检查 Java 版本是否大于 Java 中的某个迭代? [英] Check if a Java version is greater than a certain iteration in Java?

查看:24
本文介绍了检查 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 中的某个迭代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆