如何在一些参数使用java命令进行配置时,从外部配置Java应用程序。

huangapple go评论66阅读模式
英文:

How to configure java app externally when some of the arguments configure with java command

问题

我有一个Java应用程序,是通过以下命令运行的:

java -Xmx2g -jar app.jar

我无法修改java命令的执行方式。有没有办法向JVM添加额外的标志?我尝试过添加JAVA_OPTS环境变量,但没有效果。例如:

export JAVA_OPTS=-XX:+PrintFlagsFinal
java -Xmx2g -jar app.jar

不会打印标志。

英文:

I have a java app, that is run with command:

java -Xmx2g -jar app.jar

I cannot modify the way that java command is executed. Is there a way to add additional flags to the JVM? I tried to add JAVA_OPTS environment variable but it doesn't help. For example:

export JAVA_OPTS=-XX:+PrintFlagsFinal
java -Xmx2g -jar app.jar

Doesn't print flags.

答案1

得分: 1

尝试使用 _JAVA_OPTIONS,这是一个可能已被移除的未记录特性,但如果可能的话,就是这样操作。

否则,也许正在运行的 java 命令就是像那样编写的,这意味着它在你的 shell $PATH 变量中查找,这意味着你可以更改它,使其运行一个调用实际 java 的脚本,同时添加一些选项。

英文:

Try _JAVA_OPTIONS, which is an undocumented feature that probably has been removed now, but, if this is possible at all, that's how to do it.

Otherwise, perhaps the java command being run is written just like that, which means it is looked up in your shell $PATH variable, which means you can change that, and make that run a script which invokes the actual java, whilst adding a couple of options.

答案2

得分: 0

export JAVA_TOOL_OPTIONS="-XX:+PrintFlagsFinal";
/test/jre/bin/java -cp . DiskSizeCalculation17;
Picked up JAVA_TOOL_OPTIONS: -XX:+PrintFlagsFinal;
[Global flags]
intx ActiveProcessorCount = -1 {product}
uintx AdaptiveSizeDecrementScaleFactor = 4 {product}
uintx AdaptiveSizeMajorGCDecayTimeScale = 10 {product}
uintx AdaptiveSizePausePolicy = 0 {product}
uintx AdaptiveSizePolicyCollectionCostMargin = 50 {product}
uintx AdaptiveSizePolicyInitializingSteps = 20 {product}
uintx AdaptiveSizePolicyOutputInterval = 0 {product}

英文:

You may try JAVA_TOOL_OPTIONS

export JAVA_TOOL_OPTIONS="-XX:+PrintFlagsFinal"

/test/jre/bin/java -cp . DiskSizeCalculation17

Picked up JAVA_TOOL_OPTIONS: -XX:+PrintFlagsFinal
[Global flags]
     intx ActiveProcessorCount                      = -1                                  {product}
    uintx AdaptiveSizeDecrementScaleFactor          = 4                                   {product}
    uintx AdaptiveSizeMajorGCDecayTimeScale         = 10                                  {product}
    uintx AdaptiveSizePausePolicy                   = 0                                   {product}
    uintx AdaptiveSizePolicyCollectionCostMargin    = 50                                  {product}
    uintx AdaptiveSizePolicyInitializingSteps       = 20                                  {product}
    uintx AdaptiveSizePolicyOutputInterval          = 0                                   {product}

huangapple
  • 本文由 发表于 2020年9月23日 21:07:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/64028708.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定