How do I set Java's min and max heap size through environment variables? How do I set Java's min and max heap size through environment variables? java java

How do I set Java's min and max heap size through environment variables?


You can't do it using environment variables directly. You need to use the set of "non standard" options that are passed to the java command. Run: java -X for details. The options you're looking for are -Xmx and -Xms (this is "initial" heap size, so probably what you're looking for.)

Some products like Ant or Tomcat might come with a batch script that looks for the JAVA_OPTS environment variable, but it's not part of the Java runtime. If you are using one of those products, you may be able to set the variable like:

set JAVA_OPTS="-Xms128m -Xmx256m"  

You can also take this approach with your own command line like:

set JAVA_OPTS="-Xms128m -Xmx256m"  java ${JAVA_OPTS} MyClass


If you want any java process, not just ant or Tomcat, to pick up options like -Xmx use the environment variable _JAVA_OPTIONS.

In bash: export _JAVA_OPTIONS="-Xmx1g"


You can use JAVA_TOOL_OPTIONS.

Example:

export JAVA_TOOL_OPTIONS=-Xmx512m

It has been mentioned in some comments, and in another answer.

The OP's question is quite old, but as it is the first google result for the question, I thought i would add the answer here for clarity's sake.