本文介绍了-XX:OnOutOfMemoryError ="< cmd> < arg>"给出错误:无法找到或加载主类< arg>.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将JAVA_OPTS设置为

I have set JAVA_OPTS as

export JAVA_OPTS="$JAVA_OPTS -server -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:gc.log  -Dcom.sun.management.jmxremote.ssl=false -Xms100m -Xmx100m -XX:MaxPermSize=5M -XX:ReservedCodeCacheSize=100m -Xss100k -XX:NewRatio=2 -XX:+UseParallelOldGC -XX:+UseParallelGC -XX:CompileThreshold=100  -XX:HeapDumpPath=/usr/share/$package -XX:-HeapDumpOnOutOfMemoryError -XX:OnError=$TEMP_CMD -XX:OnOutOfMemoryError=$TEMP_CMD"

然后运行命令"trinidad -p"

then am running the command "trinidad -p "

在$ TEMP_CMD中,如果我使用不带任何参数的命令,则会发生OutOfMemoryError,并且$ TMP_CMD命令也将运行.但是,如果我在命令中使用任何参数,则会显示以下输出

In $TEMP_CMD, if I use command without any argument then OutOfMemoryError occurs and the $TMP_CMD command also runs. But if I use any argument with a command then the following output is shown

Error: Could not find or load main class <arg>

arg是参数

有人可以给我解决方案吗?

Can anyone give me the solution?

在trinidad.yml或任何其他cofig文件中是否要进行任何更改?

Are there any changes to be made in trinidad.yml or any other cofig file?

推荐答案

尝试

export JAVA_OPTS="... \"-XX:OnError=$TEMP_CMD\" ..."

export JAVA_OPTS='... "-XX:OnError=$TEMP_CMD" ...'

请参见 Bash嵌套的引用和eval http://www.grymoire.com/Unix/Quote.html .

更新

经过测试后,上面的内容似乎仍然无法正常工作.

The above appears still not to work after testing.

test.sh

JAVA_OPTS="$JAVA_OPTS -Xmx32m '-XX:OnOutOfMemoryError=echo %p'"
java $JAVA_OPTS Test

给予

$ bash -x ./test.sh
+ JAVA_OPTS=' -Xmx32m '\''-XX:OnOutOfMemoryError=echo %p'\'''
+ java -Xmx32m ''\''-XX:OnOutOfMemoryError=echo' '%p'\''' Test
Exception in thread "main" java.lang.NoClassDefFoundError: '-XX:OnOutOfMemoryError=echo

失败.

JAVA_OPTS="$JAVA_OPTS -Xmx32m -XX:OnOutOfMemoryError=\"echo %p\""
java $JAVA_OPTS Test

给予

$ bash -x ./test.sh
+ JAVA_OPTS=' -Xmx32m -XX:OnOutOfMemoryError="echo %p"'
+ java -Xmx32m '-XX:OnOutOfMemoryError="echo' '%p"' Test
Exception in thread "main" java.lang.NoClassDefFoundError: %p"

失败.

带有-x bash选项的诊断程序帮助Google查明了问题的根源在于bash变量替换和单词拆分规则的奇怪组合: http://mywiki.wooledge.org/BashFAQ/050 .

Diagnostics with -x bash option helped to google that the root of the problem is in a strange mix of bash variable substitution and word splitting rules: http://mywiki.wooledge.org/BashFAQ/050.

有几种可能的解决方法.

There are several possible workarounds.

1)使用帮助脚本摆脱顽固的空格

1) Use helper script to get rid of obstinate spaces

JAVA_OPTS+=" -Xmx32m -XX:OnOutOfMemoryError=/usr/tmp/test/oom.sh"
java $JAVA_OPTS Test

2)将OnOutOfMemoryError移出变量

JAVA_OPTS="$JAVA_OPTS -Xmx32m"
java $JAVA_OPTS -XX:OnOutOfMemoryError="echo %p" Test

给予

$ bash -x ./test.sh
+ JAVA_OPTS=' -Xmx32m'
+ /usr/java/jdk1.6.0_16/bin/java -Xmx32m '-XX:OnOutOfMemoryError=echo %p' Test
#
# java.lang.OutOfMemoryError: Java heap space
# -XX:OnOutOfMemoryError="echo %p"
#   Executing /bin/sh -c "echo 1639"...
1639

这篇关于-XX:OnOutOfMemoryError =&quot;&lt; cmd&gt; &lt; arg&gt;&quot;给出错误:无法找到或加载主类&lt; arg&gt;.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 12:43