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"
then am running the command "trinidad -p "
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 is the argument
Can anyone give me the solution?
Are there any changes to be made in trinidad.yml or any other cofig file?
Try
export JAVA_OPTS="... \"-XX:OnError=$TEMP_CMD\" ..."
or
export JAVA_OPTS='... "-XX:OnError=$TEMP_CMD" ...'
See Bash nested quotes and eval and http://www.grymoire.com/Unix/Quote.html.
Update
The above appears still not to work after testing.
test.sh
JAVA_OPTS="$JAVA_OPTS -Xmx32m '-XX:OnOutOfMemoryError=echo %p'"
java $JAVA_OPTS Test
gives
$ 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
fail.
JAVA_OPTS="$JAVA_OPTS -Xmx32m -XX:OnOutOfMemoryError=\"echo %p\""
java $JAVA_OPTS Test
gives
$ 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"
fail.
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) Use helper script to get rid of obstinate spaces
JAVA_OPTS+=" -Xmx32m -XX:OnOutOfMemoryError=/usr/tmp/test/oom.sh"
java $JAVA_OPTS Test
2) Move OnOutOfMemoryError
out of variable
JAVA_OPTS="$JAVA_OPTS -Xmx32m"
java $JAVA_OPTS -XX:OnOutOfMemoryError="echo %p" Test
gives
$ 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