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.
2 Answers
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:
- From the Desktop, right-click My Computer and click Properties.
- Click Advanced System Settings link in the left column.
- In the System Properties window click the Environment Variables button.
- Click New to add a new variable name and value.
- For variable name enter JAVA_OPTS for variable value enter -Xms256m -Xmx512m
- Click ok and close the System Properties Tab.
- 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.
-
This does not work, and results in an invalid heapsize definition error.– ScorbCommented 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
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.
-
-
_JAVA_OPTIONS = -Xms256m -Xmx4096m The above line solved my issue i.e. Java heap exception. Commented Jun 13, 2024 at 12:58