I have a Java program which required -Xmx1g memory. I am using Netbeans IDE for application developing. I can set this parameter from the IDE,
Right click on the project –> select ‘set configuration’ –> select ‘customize’ –> set ‘VM option’ to -Xmx1g
After setting Xmx value, programe works without any error.
But when I try to run the .jar file from the command prompt, it gives me OutOfMemory error. So I want to set this value in my Java code (e.g.: somewhere in the main method) so I can run the .jar file from the command prompt.
How do I do that?
As far as i know, you can’t do that in your java code as the jvm is already created when main get executed. But you still can use xmx switch from command line eg java -xmx1024m -jar (check the syntax, i did not).