-2

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?

8
  • just use the command line parameters, thts all the configuration settings are doing in the background. Commented Aug 12, 2012 at 11:42
  • @JonTaylor can he call command line from java code and pass to it what ever ?! Commented Aug 12, 2012 at 11:43
  • no you add the parameters to the command which runs your jar file. Commented Aug 12, 2012 at 11:45
  • @shareef can you please tell me how to do this 'call command line from java code and pass to it' Commented Aug 12, 2012 at 11:47
  • @Jon what is the command line parameter? How do I use it in command line? Commented Aug 12, 2012 at 11:47

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

Comments

0

Here's the actual syntax, and I have tested it too.

java -jar -Xmx1024m [jar_file] [args]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.