软件构造之JVM

JVM参数设置

java 知识结构图:
这里写图片描述
可见,JVM位于基础知识中比较靠后学的一部分,也是软件构造中比较难的一节课程。
关于这部分内容,官方百科给出的解释是:

Overview
Eclipse startup is controlled by the options in $ECLIPSE_HOME/eclipse.ini. If ECLIPSE_HOME is not defined, the default eclipse.ini in your Eclipse installation directory (or in the case of Mac, the Eclipse.app/Contents/MacOS directory) is used.
eclipse.ini is a text file containing command-line options that are added to the command line used when Eclipse is started up. There are many options available, please see here.
Important:
You can, and should, experiment with changes to the launch command from your Command Prompt/Terminal before changing the eclipse.ini itself.
Each option and each argument to an option must be on its own line.
All lines after -vmargs are passed as arguments to the JVM, so all arguments and options for eclipse must be specified before -vmargs (just like when you use arguments on the command-line)
Any use of -vmargs on the command-line replaces all -vmargs settings in the .ini file unless –launcher.appendVmargs is specified either in the .ini file or on the command-line. (doc)
-XX VM arguments are subject to change without notice, even during minor updates. If the JVM keeps exiting with code 2 instead of starting Eclipse, try removing them.
Make a backup–keep a copy of the original contents on hand so you don’t break your installation and have to download it all again.
By default, eclipse.ini looks something like this (the exact contents will vary based on operating system and which Eclipse package you have):

翻译如下:

概观
Eclipse启动由$ ECLIPSE_HOME / eclipse.ini中的选项控制。如果未定义ECLIPSE_HOME,则使用Eclipse安装目录中的默认eclipse.ini(或Mac,Eclipse.app/Contents/MacOS目录)。
eclipse.ini是一个包含命令行选项的文本文件,添加到Eclipse启动时使用的命令行中。有很多选择,请看这里。
重要:
在更改eclipse.ini之前,您可以并应该尝试更改命令提示符/终端中的启动命令。
每个选项和选项的每个参数都必须独立。
-vmargs之后的所有行都作为参数传递给JVM,因此所有的eclipse参数和选项必须在-vmargs之前指定(就像在命令行中使用参数一样)
在命令行上使用-vmargs会替换.ini文件中的所有-vmargs设置,除非在.ini文件或命令行中指定了–launcher.appendVmargs。 (DOC)
-XX VM参数如有更改,恕不另行通知,即使在微小更新期间也是如此。如果JVM保持退出代码2而不是启动Eclipse,请尝试删除它们。
进行备份 - 保留手头原始内容的副本,以免破坏安装并重新下载。
默认情况下,eclipse.ini看起来像这样(确切的内容会根据操作系统和您拥有的Eclipse包而有所不同):

默认构造参数为:

-startup
../../../plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
–launcher.library
../../../plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.100.v20110502
-product
org.eclipse.epp.package.jee.product
–launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
256m
–launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-XX:MaxPermSize=256m
-Xms40m
-Xmx512m

最常用到这项任务的是指定一个特定的JVM供Eclipse运行。这样做可以确保您完全确定将运行什么样的JVM Eclipse,并使您免受可能会改变系统“默认”JVM的系统更改的影响。许多用户被绊倒了,因为他们认为他们知道默认使用什么JVM,但他们认为是错误的。 eclipse.ini对这更加确定。

以下eclipse.ini示例演示了-vm选项的正确用法。

请注意-vm选项的格式 - 严格来说非常重要:

-vm选项及其值(路径)必须位于不同的行上。
该值必须是Java可执行文件的完整绝对路径或相对路径,而不仅限于Java主目录。
-vm选项必须在其他特定于Eclipse的选项(例如-product,–launcher。*等)之后,但在-vmargs选项之前发生,因为-vmargs之后的所有内容都直接传递给JVM。
对于32位Eclipse可执行文件(Windows上的eclipse.exe),必须使用32位JVM;对于64位Eclipse可执行文件,必须使用64位JVM。

配置JVM参数实例

-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
–launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.100.v20110502
-product
org.eclipse.epp.package.java.product
–launcher.defaultAction
openFile
–launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
256m
–launcher.defaultAction
openFile
-vm
C:\Java\JDK\1.8\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx1024m

扫描二维码关注公众号,回复: 1601989 查看本文章

Windows cmd实例

-vm
C:\jdk1.7.0_21\bin\javaw.exe
这个命令行可以显示已经配置的JVM参数

猜你喜欢

转载自blog.csdn.net/weixin_39584132/article/details/80691013
今日推荐