<i id='IGlNP'><tr id='IGlNP'><dt id='IGlNP'><q id='IGlNP'><span id='IGlNP'><b id='IGlNP'><form id='IGlNP'><ins id='IGlNP'></ins><ul id='IGlNP'></ul><sub id='IGlNP'></sub></form><legend id='IGlNP'></legend><bdo id='IGlNP'><pre id='IGlNP'><center id='IGlNP'></center></pre></bdo></b><th id='IGlNP'></th></span></q></dt></tr></i><div id='IGlNP'><tfoot id='IGlNP'></tfoot><dl id='IGlNP'><fieldset id='IGlNP'></fieldset></dl></div>

    <tfoot id='IGlNP'></tfoot>
    <legend id='IGlNP'><style id='IGlNP'><dir id='IGlNP'><q id='IGlNP'></q></dir></style></legend>
      <bdo id='IGlNP'></bdo><ul id='IGlNP'></ul>
  1. <small id='IGlNP'></small><noframes id='IGlNP'>

      Java 系统环境变量

      Java System Environment Variable(Java 系统环境变量)

      <small id='EfSrc'></small><noframes id='EfSrc'>

          <bdo id='EfSrc'></bdo><ul id='EfSrc'></ul>
          <tfoot id='EfSrc'></tfoot>

            <tbody id='EfSrc'></tbody>
              <legend id='EfSrc'><style id='EfSrc'><dir id='EfSrc'><q id='EfSrc'></q></dir></style></legend>
                <i id='EfSrc'><tr id='EfSrc'><dt id='EfSrc'><q id='EfSrc'><span id='EfSrc'><b id='EfSrc'><form id='EfSrc'><ins id='EfSrc'></ins><ul id='EfSrc'></ul><sub id='EfSrc'></sub></form><legend id='EfSrc'></legend><bdo id='EfSrc'><pre id='EfSrc'><center id='EfSrc'></center></pre></bdo></b><th id='EfSrc'></th></span></q></dt></tr></i><div id='EfSrc'><tfoot id='EfSrc'></tfoot><dl id='EfSrc'><fieldset id='EfSrc'></fieldset></dl></div>
              • 本文介绍了Java 系统环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Java 是否有一个默认的系统环境变量,当我们设置它时总是会被读取/附加?CATALINA_OTPS/JAVA_OPTS 等似乎只适用于 TOMCAT/JBOSS 等.

                Does Java have a default System Environment Variable that will always be read/appended when we set it? CATALINA_OTPS/JAVA_OPTS etc seems only for TOMCAT/JBOSS etc.

                1. 我不想通过 Java 系统属性(通过 -Dprop1=value1 -Dprop2=value2 传入)设置它,因为它涉及 shell/batch 脚本.
                2. 它应该可以跨操作系统工作,就像在 Windows 中双击 jar 文件一样.
                3. 它应该适用于不同的 JRE(Sun、IBM、OpenJDK 等).
                4. 不应涉及额外的编码.
                5. 它应该可以在大多数库配置文件中使用,例如设置 log4j级别 ${LOG_LEVEL}.

                更新:添加了第 4 项和第 5 项.从标题中删除 OS 以使我的问题更清楚.

                Update: Added item # 4 and 5. Remove OS from title to make my question clearer.

                Update 2:看了 Perception 的回答后,我的第 2 和第 3 项似乎可以通过 System.getenv 实现.第4、5项如何实现?

                Update 2: After looking at Perception's answer, it seems like my item 2 and 3 can be achieved via System.getenv. How to achieve item 4 and 5?

                以下是场景示例:现在想象一下,JAVA_DEFAULT_OPTS 是一个环境变量,Java 将读取它,因为它现在已成为标准.在开发台式机上,我设置 JAVA_DEFAULT_OPTS=-DLOG_LEVEL=DEBUG -Xmx384m;在生产服务器机器上,客户设置 JAVA_DEFAULT_OPTS=-DLOG_LEVEL=INFO -Xmx1024m.当我/用户在 Windows 上双击 jar 文件时,应用程序将运行不同的 log4j 级别和最大内存堆大小.

                Here is example of scenario: Imagine now JAVA_DEFAULT_OPTS is an environment variable that will be read by Java as it has now become the standard. On development desktop machine, I set JAVA_DEFAULT_OPTS=-DLOG_LEVEL=DEBUG -Xmx384m; On production server machine, customers set JAVA_DEFAULT_OPTS=-DLOG_LEVEL=INFO -Xmx1024m. When I/users double click the jar file on Windows, the application will run will different log4j level and max memory heap size.

                推荐答案

                有一个特殊的环境变量叫做_JAVA_OPTIONS,它的值会被JVM(java.exe)拾取.

                There is a special environment variable called _JAVA_OPTIONS, its value will be picked up by the JVM (java.exe).

                在 Windows 中:

                In Windows:

                set _JAVA_OPTIONS=-Xms64m -Xmx128m -Dawt.useSystemAAFontSettings=lcd
                

                在 Linux 中:

                export _JAVA_OPTIONS='-Xms64m -Xmx128m -Dawt.useSystemAAFontSettings=lcd'
                

                对于 Java Web Start,它是 JAVAWS_VM_ARGS.对于 javaw.exe (Applet),它是 _JPI_VM_OPTIONS.

                For Java Web Start it's JAVAWS_VM_ARGS. For javaw.exe (Applet), it's _JPI_VM_OPTIONS.

                编辑 20201213

                _JAVA_OPTIONS 环境变量没问题,但没有记录或支持.

                _JAVA_OPTIONS environment variable was ok but was not documented or supported.

                由于没有标准化,其他供应商都有自己的名称,例如IBM_JAVA_OPTIONS.按照惯例,前导下划线名称是私有的,因此标准化 _JAVA_OPTIONS 的使用并不是一个好主意.

                Since it is not standardized, other vendors have their own names e.g. IBM_JAVA_OPTIONS. Leading underscore names are private by convention so it's not a good idea to standardize the usage of _JAVA_OPTIONS.

                这就是为什么 JAVA_TOOL_OPTIONS 应该是首选的原因.

                That's why JAVA_TOOL_OPTIONS should be the preferred choice.

                参考:https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#tooloptions

                这篇关于Java 系统环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Maven JAVA_HOME environment variable is not defined correctly, but it is(Maven JAVA_HOME 环境变量未正确定义,但它是)
                Java -classpath option(Java -classpath 选项)
                Read environment variable in SpringBoot(在 SpringBoot 中读取环境变量)
                Tomcat 8 - context.xml use Environment Variable in Datasource(Tomcat 8 - context.xml 在数据源中使用环境变量)
                Issue with JAVA_HOME(JAVA_HOME 的问题)
                Access shell environment variables in Java(在 Java 中访问 shell 环境变量)
                  <tbody id='TfFDZ'></tbody>

                  <small id='TfFDZ'></small><noframes id='TfFDZ'>

                  <i id='TfFDZ'><tr id='TfFDZ'><dt id='TfFDZ'><q id='TfFDZ'><span id='TfFDZ'><b id='TfFDZ'><form id='TfFDZ'><ins id='TfFDZ'></ins><ul id='TfFDZ'></ul><sub id='TfFDZ'></sub></form><legend id='TfFDZ'></legend><bdo id='TfFDZ'><pre id='TfFDZ'><center id='TfFDZ'></center></pre></bdo></b><th id='TfFDZ'></th></span></q></dt></tr></i><div id='TfFDZ'><tfoot id='TfFDZ'></tfoot><dl id='TfFDZ'><fieldset id='TfFDZ'></fieldset></dl></div>
                    <bdo id='TfFDZ'></bdo><ul id='TfFDZ'></ul>

                    <legend id='TfFDZ'><style id='TfFDZ'><dir id='TfFDZ'><q id='TfFDZ'></q></dir></style></legend>

                      • <tfoot id='TfFDZ'></tfoot>