有没有办法找到安装在OS X上的所有Java版本的完整列表?

huangapple go评论71阅读模式
英文:

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:	&quot;OpenJDK 13&quot;	/Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home
    1.8.0_265, x86_64:	&quot;AdoptOpenJDK 8&quot;	/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&#39;s settings.

Options:
    [-v/--version   &lt;version&gt;]       Filter Java versions in the &quot;JVMVersion&quot; form 1.X(+ or *).
    [-a/--arch      &lt;architecture&gt;]  Filter JVMs matching architecture (i386, x86_64, etc).
    [-d/--datamodel &lt;datamodel&gt;]     Filter JVMs capable of -d32 or -d64
    [-t/--task      &lt;task&gt;]          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      &lt;command&gt; ...]   Execute the $JAVA_HOME/bin/&lt;command&gt; 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

huangapple
  • 本文由 发表于 2020年8月30日 15:12:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/63654909.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定