如何在用户尝试运行应用程序之前检查安装的Java版本?

时间:2022-03-25 20:26:50

If a user double-clicks on an executable JAR file, is it possible to check what version of Java that he or she has installed, and then display an appropriate message in a window that says that he or she needs to have X version of Java to run the application?

如果用户双击可执行JAR文件,是否可以检查他或她安装的Java版本,然后在窗口中显示相应的消息,表明他或她需要拥有X版本的Java运行应用程序?

I am creating an application that requires Java 7, and if a user does not have that version installed, I would like to display a message that says that he or she needs to download and install it.

我正在创建一个需要Java 7的应用程序,如果用户没有安装该版本,我想显示一条消息,说明他或她需要下载并安装它。

Of course, the user can type java -version, but it would be nice to display the version in a window for those who don't know how to check what version is installed. Is it possible to do so?

当然,用户可以键入java -version,但是对于那些不知道如何检查安装的版本的人来说,在窗口中显示版本会很不错。有可能这样做吗?

Or should I run some type of script to check before launching the application?

或者我应该在启动应用程序之前运行某种类型的脚本来检查?

2 个解决方案

#1


3  

Check the System.getProperty("java.version")

检查System.getProperty(“java.version”)

You'll need to do some parsing, but this should give you a jumping of point

你需要做一些解析,但这应该给你一个跳跃点

#2


2  

You can get the java version by using System.getProperty("java.version")

您可以使用System.getProperty(“java.version”)获取Java版本

See the documentation (http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html)

请参阅文档(http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html)

#1


3  

Check the System.getProperty("java.version")

检查System.getProperty(“java.version”)

You'll need to do some parsing, but this should give you a jumping of point

你需要做一些解析,但这应该给你一个跳跃点

#2


2  

You can get the java version by using System.getProperty("java.version")

您可以使用System.getProperty(“java.version”)获取Java版本

See the documentation (http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html)

请参阅文档(http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html)