英文:
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。
提前谢谢
英文:
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:
<vmSettings defaultVM="57,org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType13,1597823290779" defaultVMConnector="">
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
答案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>&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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论