Programmatically determine what JDK/JRE's are installed on my box

前端 未结 3 1241
旧时难觅i
旧时难觅i 2021-01-02 06:18

Is there a standard way to do this? I realize this can be somewhat platform dependent. Our product right now is only supported on Windows - so I suppose that\'s what I\'m

相关标签:
3条回答
  • 2021-01-02 06:45
    System.out.println(System.getProperty("java.version"));
    

    Other properties here

    0 讨论(0)
  • 2021-01-02 06:53

    I would firstly start by looking for the JAVA_HOME environment variable (and possibly JDK_HOME although thats far less common) and then determining what version that is and whether it's a JDK or JRE.

    After that check for common instead locations. Find out the system's program files directory (don't just assume it's C:\Program Files even though it is 99.5% of the time) and look for common install locations under that (eg Java).

    I wouldn't do an exhaustive search.

    It's worth asking: do you really need to find JDKs this way? Can't you just ask the user what JDK he or she wishes to use, possibly suggesting any easy ones you've found already?

    0 讨论(0)
  • 2021-01-02 06:59

    I'd probably go for a combination of looking for the Java installed registry keys and crawling the default locations for installation (which shouldn't take too long).

    An alternative approach would be to bundle a tiny Java application which prints various details such as the running JVM.

    0 讨论(0)
提交回复
热议问题