英文:
Is there a way to find the complete list of Java versions installed on OS X?
问题
我试图查找安装在我Mac OS X上的完整JDK版本列表。
我尝试过使用 javac -version,但它只显示在bashrc中设置的当前版本。
任何帮助将不胜感激。
英文:
I was trying to find the complete list of JDK versions installed on my Mac OS X.
I did try with javac -version but it only shows the current version that is set in bashrc.
Any help would be appreciated.
答案1
得分: 13
Mac OS X有一个很酷的二进制文件(/usr/libexec/java_home),它可以从当前用户的设置中返回Java主目录的路径。您可以执行以下操作:
/usr/libexec/java_home -V
它会打印出带有架构的完整JVM列表,类似于这样:
匹配的Java虚拟机(2):
    13,x86_64:“OpenJDK 13”	/Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home
    1.8.0_265,x86_64:“AdoptOpenJDK 8”	/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home
如果您想要打印特定JDK版本的JAVA_HOME路径,可以像这样操作:
/usr/libexec/java_home -v 1.8
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
您可以查看以下完整的使用选项:
用法:java_home [选项...]
    从当前用户的设置中返回Java主目录的路径。
选项:
    [-v/--version   <version>]       过滤以“JVMVersion”形式为1.X(+或*)的Java版本。
    [-a/--arch      <architecture>]  过滤与架构匹配的JVM(i386、x86_64等)。
    [-d/--datamodel <datamodel>]     过滤支持-d32或-d64的JVM。
    [-t/--task      <task>]          使用特定任务的JVM列表(Applets、WebStart、BundledApp、JNI或CommandLine)
    [-F/--failfast]                  当过滤器未返回任何JVM时失败,不继续使用默认值。
    [--exec         <command> ...]   使用剩余的参数执行$JAVA_HOME/bin/<command>。
    [-R/--request]                   请求安装Java Runtime(如果未安装)。
    [-X/--xml]                       打印完整的JVM列表和额外的XML plist数据。
    [-V/--verbose]                   打印带有架构的完整JVM列表。
    [-h/--help]                      此使用信息。
英文:
Mac OS X has a cool binary (/usr/libexec/java_home) that returns the path to a Java home directory from the current user's settings. You may want to issue:
/usr/libexec/java_home -V
It prints the full JVM list with architectures like this:
Matching Java Virtual Machines (2):
    13, x86_64:	"OpenJDK 13"	/Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home
    1.8.0_265, x86_64:	"AdoptOpenJDK 8"	/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home
If you want to print the JAVA_HOME path of a specific JDK version, you can do it like this:
/usr/libexec/java_home -v 1.8
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
You can see the complete usage options of below:
Usage: java_home [options...]
    Returns the path to a Java home directory from the current user's settings.
Options:
    [-v/--version   <version>]       Filter Java versions in the "JVMVersion" form 1.X(+ or *).
    [-a/--arch      <architecture>]  Filter JVMs matching architecture (i386, x86_64, etc).
    [-d/--datamodel <datamodel>]     Filter JVMs capable of -d32 or -d64
    [-t/--task      <task>]          Use the JVM list for a specific task (Applets, WebStart, BundledApp, JNI, or CommandLine)
    [-F/--failfast]                  Fail when filters return no JVMs, do not continue with default.
    [   --exec      <command> ...]   Execute the $JAVA_HOME/bin/<command> with the remaining arguments.
    [-R/--request]                   Request installation of a Java Runtime if not installed.
    [-X/--xml]                       Print full JVM list and additional data as XML plist.
    [-V/--verbose]                   Print full JVM list with architectures.
    [-h/--help]                      This usage information.
答案2
得分: 3
你可以使用 java_home 二进制文件来完成这个任务。
/usr/libexec 包含一些不打算由用户或者Shell脚本直接执行的内部二进制文件。java_home 就是其中之一,使用选项 -V 调用它会打印带有架构的完整JVM列表。
     /usr/libexec/java_home -V
英文:
You can use the java_home binary for this task.
/usr/libexec includes internal binaries that are not intended to be executed directly by users or shell scripts. java_home is one such binary, calling it with option -V will print full JVM list with architectures.
     /usr/libexec/java_home -V
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论