0

I want to set the default Java heap size to 1024m without needing to specify the -Xmx option every time I run a jar file.

Tried adding export JAVA_OPTIONS=-Xmx1024m to .bashrc file but it didn't work.

3

2 Answers 2

1

The maximum heap size is not the maximum amount of memory the JVM will use, but the heap size is what Xmx actually sets.

Regarding settings, it seems there maybe issues with JAVA_OPTIONS, a more bulletproof method would be to add this to .bashrc:

alias java='java -Xms1024m'

Or, since environment variables are interpolated in an alias:

alias java='java $MY_JAVA_OPTS'
export MY_JAVA_OPTS="-Xms1024m"

This gives you some flexibility if you want to add or override $MY_JAVA_OPTS for some session:

MY_JAVA_OPTS="$MY_JAVA_OPTS -Xprof -Xdiag"
0

Solved this by adding export _JAVA_OPTIONS=-Xmx1024m to /etc/profile file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.