Java check latest version programmatically

前端 未结 9 1672
不思量自难忘°
不思量自难忘° 2020-12-14 02:36

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

I woul

9条回答
  •  猫巷女王i
    2020-12-14 03:19

    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 code example

    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
    }
    

    Update 2014-03-20

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

    Update 2016-07-13

    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.

    Update 2018-08-19

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

提交回复
热议问题