Search code examples
javawindows-7java-homesystem-variable

Problems with System.getProperty("java.home")


I run Windows 7 with different JRE/JDKs installed. I try to set the JAVA_HOME path to "C:\Program Files\Java\jdk1.8.0_45". I tried multiple ways to do that like described in How to set java_home on Windows 7?.

I think it worked, because in the advanced System Properties, the new path is shown and the command echo %JAVA_HOME% also returns the new path. But when I invoke the following program via cmd

public class JavaVersionShower {
    public static void main(String[] args){
        JOptionPane.showMessageDialog(null, System.getProperty("java.home"));
    }
}

the message window says "C:\Program Files\Java\jre1.8.0_66". I also cannot use the JavaCompiler API which is only available if the used java version is a jdk.


Solution

  • Updating java home and path is little different in windows 7 and 8. You might need to go to "C:\ProgramData\Oracle\Java\javapath" to update them. This article might be helpful to you Update Java path in Windows 8

    Ravi