Java以编程方式检查最新版本 [英] Java check latest version programmatically

查看:117
本文介绍了Java以编程方式检查最新版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:检查机器上的java版本(我可以从 java -version 获取)。将其与最新版本的 java网站进行比较

Goal: check java's version on a machine (I can get this from java -version). Compare it with latest available from java website

我想知道是否有任何方法可以检查最新的Java版本,假设我在一台机器上安装了JRE / JDK。

I would like to know if there is any way I can check for latest Java releases assuming that I have JRE/JDK installed on a machine.

如果我可以通过Java本身做到这一点,我的解决方案将变得与平台无关。我可以使用 java.net.URL 类向Java网站发送请求并获取HTML,但是响应将是动态的,因为Oracle可以更改其网站和样式,并且可能从长远来看会有维护问题。

If I can do this through Java itself, my solution would become platform independent. I could use java.net.URL class to send a request to Java website and get the HTML, however the response would be dynamic as Oracle can change their website and styles and possibly will have maintenance issues in long run.

我看过 javatester.org ,但我不希望它通过applet而是通过命令行(我可以添加到脚本中)。

I have looked at javatester.org, but I would not want it through an applet but through command line (which I can add to a script).

通过javacpl.exe,我可以安排定期检查,但我想按需进行。

Through javacpl.exe, I can schedule periodic checks, but I would like to do it on demand.

推荐答案

答案实际上是相当的简单。 http://java.com/en/download/testjava.jsp 发出请求 http://java.com/applet/JreCurrentVersion2.txt 。该文件目前包含一个版本号:'1.7.0_11'...这是最新的,也是最好的。

The answer is actually quite simple. http://java.com/en/download/testjava.jsp issues a request to http://java.com/applet/JreCurrentVersion2.txt. That file currently contains a single version number: '1.7.0_11'...which is the latest and greatest, indeed.

Java代码示例

try (BufferedReader br = new BufferedReader(new InputStreamReader(new URL(
    "http://java.com/applet/JreCurrentVersion2.txt").openStream()))) {
  String fullVersion = br.readLine();
  String version = fullVersion.split("_")[0];
  String revision = fullVersion.split("_")[1];
  System.out.println("Version " + version + " revision " + revision);
} catch (IOException e) {
  // handle properly
}

更新2014-03-20

尽管 Java 8最近发布了 http://java.com/applet/JreCurrentVersion2.txt 目前仍然返回1.7.0_51。

Eventhough Java 8 was recently released http://java.com/applet/JreCurrentVersion2.txt currently still returns 1.7.0_51.

更新2016-07-13

看起来我们需要每隔几个月回到这个......目前你需要扫描 http://java.com/en/download/installed8.jsp 获取JavaScript变量 latest8Version 。所以,你可以运行 curl -s https://java.com/en/download/installed8.jsp | grep latest8Version

Looks like we need to come back to this every few months... Currently you need to scan http://java.com/en/download/installed8.jsp for a JavaScript variable latest8Version. So, you could run curl -s https://java.com/en/download/installed8.jsp | grep latest8Version.

更新2018-08-19

http://javadl-esd-secure.oracle.com/update /baseline.version 是其他答案中提到的另一个热点。

http://javadl-esd-secure.oracle.com/update/baseline.version is another hot spot as mentioned in some other answer.

这篇关于Java以编程方式检查最新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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