从命令行获取Java兼容性级别信息。

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

Get Java compliance level information from command line

问题

我使用Java 14,并且我想为Eclipse编写一个自动配置脚本,以防我在计算机上更新Java。Eclipse使用以下行来指定默认的Java虚拟机:

<vmSettings defaultVM="57,org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType13,1597823290779" defaultVMConnector=""/>

正如您所看到的,在"defaultVM"属性中的第一个参数是兼容级别,我不知道如何从java命令中获取此值(在本例中为"57")。"java --version"只给出"14.0.2",但这不是兼容级别。是否有其他参数可以在命令行上获取兼容级别?然后我将使用PowerShell命令解析并评估它。其他像"javac"之类的命令也可用,因为我正在安装来自zip分发包的OpenJDK。

提前谢谢 从命令行获取Java兼容性级别信息。

英文:

I use Java 14 and I want to write a auto configuration script for Eclipse in case I update Java on my machine. Eclipse uses the following line to specify the default Java VM:

&lt;vmSettings defaultVM=&quot;57,org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType13,1597823290779&quot; defaultVMConnector=&quot;&quot;&gt;

As you can see, the first parameter in the "defaultVM" attribute is the compliance level and I have no idea on how to get this value (in this case "57") from the java command. "java --version" gives me only "14.0.2" but this is not the compliance level. Is there some other parameter on how to get the compliance level on command line? I would then parse and evaluate it with PowerShell commands. Other commands like "javac" are also usable because I am installing OpenJDK from the zip redist package.

Thanks in advance 从命令行获取Java兼容性级别信息。

答案1

得分: 1

java -XshowSettings:all 将显示所有可用的值。java -X 将显示可用的选项。也就是说,您仍然需要进行一些翻译。看起来 "compliance level" 可能对应于 java.class.version(主要)版本:

$ $(/usr/libexec/java_home -v 13)/bin/java -XshowSettings:all 2>&1 | grep java.class.version
    java.class.version = 57.0
$ $(/usr/libexec/java_home -v 14)/bin/java -XshowSettings:all 2>&1 | grep java.class.version
    java.class.version = 58.0
英文:

java -XshowSettings:all will show all available values. java -X will show the available options. That said, you'll still need to do some translation. It looks like "compliance level" may correspond to java.class.version (major) version:

$ $(/usr/libexec/java_home -v 13)/bin/java -XshowSettings:all 2&gt;&amp;1 | grep java.class.version
    java.class.version = 57.0
$ $(/usr/libexec/java_home -v 14)/bin/java -XshowSettings:all 2&gt;&amp;1 | grep java.class.version
    java.class.version = 58.0

huangapple
  • 本文由 发表于 2020年8月19日 17:45:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63484255.html
匿名

发表评论

匿名网友

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

确定