1

我有以下序列

ubuntu@ip-10-63-3-254:/mnt$ export JAVA_OPTS=-Dmt.config.from=En
ubuntu@ip-10-63-3-254:/mnt$ echo $JAVA_OPTS
-Dmt.config.from=En
ubuntu@ip-10-63-3-254:/mnt$ javac hello.java
ubuntu@ip-10-63-3-254:/mnt$ java 你好
mt.config.from=null
ubuntu@ip-10-63-3-254:/mnt$ java -Dmt.config.from=En 你好
mt.config.from=En
ubuntu@ip-10-63-3-254:/mnt$

hello.java 在哪里

公共课你好{
公共静态无效主要(字符串[]参数){
       字符串属性 = "mt.config.from";
       字符串值 = System.getProperty(property);
       System.out.println(property + "=" + value);
  }
}

为什么我的 export JAVA_OPTS=-Dmt.config.from=En 没有被 hello.java 选中?谢谢

4

1 回答 1

5

我认为您在运行时需要参考$JAVA_OPTS,例如:

java $JAVA_OPTS hello

我认为根本不java检查环境变量,它更像是启动 jvm 时脚本中使用的约定。

于 2013-04-09T13:17:51.947 回答