Search code examples
corretto

Can I programmatically detect if Corretto Java is installed and which version?


Amazon Corretto is a replacement to Oracle JRE/JDK.

Is there a way to detect if Corretto is installed (on windows machine) programmatically and if installed - which version ?


Solution

  • You can check if the Default installed JDK is Amazon Corretto by checking the JAVA_HOME path, and if it's you can get the version from the path for example

    String javaHomePath = System.getProperty("java.home");
    if (javaHomePath.contains("corretto")) {
                
    }
    

    Or you check if it installed but not default by checking the list of files in the JAVA_HOME parent directory for example

    File file = new File(javaHomePath);
    File[] jvmFiles = file.getParentFile().listFiles();
    for (File jvmFile : jvmFiles) {
        if (jvmFile.getPath().contains("corretto")) {
            String amazonCorrettoPath = jvmFile.getPath();
        }
    }