java系统环境变量,Java系统环境变量

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.

I do not want to set it through Java system properties (which is passed in via -Dprop1=value1 -Dprop2=value2) as it involves shell/batch script.

It should work across OS, like double click jar file in Windows.

It should work across different JREs (Sun, IBM, OpenJDK etc).

It should not involve extra coding.

It should work in most libraries configuration file, like setting log4j

level ${LOG_LEVEL}.

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

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?

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.

解决方案

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

In Windows:

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

In Linux:

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值