24

I want to set Java heap size permanently and don't want to run every jar file with options. I use Windows and Java 1.7.

0

2 Answers 2

69

Setup JAVA_OPTS as a system variable with the following content:

JAVA_OPTS="-Xms256m -Xmx512m"

After that in a command prompt run the following commands:

SET JAVA_OPTS="-Xms256m -Xmx512m"

This can be explained as follows:

  • allocate at minimum 256MBs of heap
  • allocate at maximum 512MBs of heap

These values should be changed according to application requirements.

EDIT:

You can also try adding it through the Environment Properties menu which can be found at:

  1. From the Desktop, right-click My Computer and click Properties.
  2. Click Advanced System Settings link in the left column.
  3. In the System Properties window click the Environment Variables button.
  4. Click New to add a new variable name and value.
  5. For variable name enter JAVA_OPTS for variable value enter -Xms256m -Xmx512m
  6. Click ok and close the System Properties Tab.
  7. Restart any java applications.

EDIT 2:

JAVA_OPTS is a system variable that stores various settings/configurations for your local Java Virtual Machine. By having JAVA_OPTS set as a system variable all applications running on top of the JVM will take their settings from this parameter.

To setup a system variable you have to complete the steps listed above from 1 to 4.

2
  • This does not work, and results in an invalid heapsize definition error.
    – Scorb
    Commented Nov 7, 2023 at 21:51
  • @Scorb this worked in 2013 for sure, feel free to suggest edits to what works for current Windows versions and I'll gladly accept them Commented Nov 11, 2023 at 10:36
21

Try setting a Windows System Environment variable called _JAVA_OPTIONS with the heap size you want. Java should be able to find it and act accordingly.

2
  • How to format that variable value please ?.. Commented Dec 13, 2021 at 19:55
  • _JAVA_OPTIONS = -Xms256m -Xmx4096m The above line solved my issue i.e. Java heap exception. Commented Jun 13, 2024 at 12:58

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.