聊聊openjdk的jvm.cfg文件
Posted 码匠的流水账
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了聊聊openjdk的jvm.cfg文件相关的知识,希望对你有一定的参考价值。
序
本文主要研究一下openjdk的jvm.cfg文件
jdk8
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/jvm.cfg
# List of JVMs that can be used as an option to java, javac, etc.
# Order is important -- first in this list is the default JVM.
# NOTE that this both this file and its format are UNSUPPORTED and
# WILL GO AWAY in a future release.
#
# You may also select a JVM in an arbitrary location with the
# "-XXaltjvm=<jvm_dir>" option, but that too is unsupported
# and may not be available in a future release.
#
-server KNOWN
-client IGNORE
对于jdk8该文件在JAVA_HOME/jre/lib/目录下;其注释显示该配置文件用于配置java、javac能够使用的option,其中配置顺序非常重要,第一个为default JVM(
不管其是KNOWN还是IGNORE;IGNORE仅仅是禁用VM option;ERROR则报错显示not supported
);可以看到这里-server是默认的,而-client则被忽略
jdk9-12
/Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home/lib/jvm.cfg
-server KNOWN
-client IGNORE
对于jdk9、10、11、12该文件在JAVA_HOME/lib/目录下
设置-client为default
对于jdk12,把-client移到前面
-client IGNORE
-server KNOWN
执行java -version显示如下
java -version
Error: missing `client' JVM at `/Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home/lib/client/libjvm.dylib'.
Please install or use the JRE or JDK that contains these missing components.
可以看到对于mac的jdk12,把client设置为default则报错
禁用client
-server KNOWN
-client ERROR
执行java -client -version显示如下
java -client -version
Error: client VM not supported
可以看到设置-client为ERROR,则报错显示not supported
删除jvm.cfg
java -version
Error: could not open `/Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home/lib/jvm.cfg'
可以看到删除jvm.cfg,执行java -version则会报错
小结
jvm.cfg文件用于配置java、javac能够使用的option,其中配置顺序非常重要,第一个为default JVM(
不管其是KNOWN还是IGNORE;IGNORE仅仅是禁用VM option;ERROR则报错显示not supported
)对于jdk8该文件在JAVA_HOME/jre/lib/目录下;对于jdk9、10、11、12该文件在JAVA_HOME/lib/目录下;删除jvm.cfg文件的话,则执行java命令会报错
可以看到对于mac来说其open jdk的jvm.cfg中-server位于-client前面,-server是default JVM,而-client被忽略
doc
The Java HotSpot VM Architecture Overview
What is the purpose of jvm.cfg file in relation to Java?
Running the JVM in server mode
Server-Class Machine Detection
Change Default Java VM to Client
OpenJDK default options to always use the server VM
以上是关于聊聊openjdk的jvm.cfg文件的主要内容,如果未能解决你的问题,请参考以下文章
Error: could not open `D:\JAVA\lib\i386\jvm.cfg'这是怎么回事?
Error: could not open `E:\新建文件夹\lib\amd64\jvm.cfg'是啥意思,怎么弄
Eclipse无法打开提示could not open jvm.cfg错误