聊聊openjdk的jvm.cfg文件

本文主要研究一下openjdk的jvm.cfg文件html

jdk8

/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/jvm.cfgjava

# 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則被忽略ubuntu

jdk9-12

/Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home/lib/jvm.cfgoracle

-server KNOWN
-client IGNORE

對於jdk九、十、十一、12該文件在JAVA_HOME/lib/目錄下jvm

設置-client爲default

對於jdk12,把-client移到前面ide

-client IGNORE
-server KNOWN

執行java -version顯示以下ui

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則報錯this

禁用client

-server KNOWN
-client ERROR

執行java -client -version顯示以下code

java -client -version
Error: client VM not supported

能夠看到設置-client爲ERROR,則報錯顯示not supportedcomponent

刪除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/目錄下;對於jdk九、十、十一、12該文件在JAVA_HOME/lib/目錄下;刪除jvm.cfg文件的話,則執行java命令會報錯
  • 能夠看到對於mac來講其open jdk的jvm.cfg中-server位於-client前面,-server是default JVM,而-client被忽略

doc

相關文章
相關標籤/搜索