5

I am able to run a Java program through Eclipse by setting the VM arguments as -Xmx1024m -Xms256M. Now I want to run the same Java program (jar) through a .bat file in Windows. I am setting the JVM values in the file as follows

@echo off
set JAVA_OPTS="-Xmx1024m -Xms256m -XX:+HeapDumpOnOutOfMemoryError"
java -cp TA.jar com.myClass

But when I run the same program through batch (.bat in Windows XP) it throws Out of Memory error and I suspect that the JVM setting through the .bat file is not working.

7
  • Have you tried simply passing the options instead of setting the environment variable?
    – Michael Myers
    Jan 31, 2013 at 19:56
  • @Michael Myers I didnt quite understand what you meant.. sorry..
    – IS_EV
    Jan 31, 2013 at 20:03
  • 2
    I mean java -Xmx1024m -Xms256m -XX:+HeapDumpOnOutOfMemoryError -cp TA.jar com.myClass instead of messing with JAVA_OPTS
    – Michael Myers
    Jan 31, 2013 at 20:04
  • 1
    possible dupe? stackoverflow.com/questions/2011311/…
    – sharakan
    Jan 31, 2013 at 20:06
  • @MichaelMyers: When I tried that it is showing the error - Could not find or load main class Xmx1024m
    – IS_EV
    Jan 31, 2013 at 20:12

2 Answers 2

11

It should be _JAVA_OPTIONS instead of JAVA_OPTS.

2
  • 1
    Thanks Danyel.. It worked.. I used : set _JAVA_OPTIONS=-Xmx1024m -Xms256m -XX:+HeapDumpOnOutOfMemoryError
    – IS_EV
    Jan 31, 2013 at 20:17
  • this should be the real answer
    – sam-6174
    Apr 8, 2015 at 15:23
3

Use the arguments directly

java -Xmx1024m -Xms256m -XX:+HeapDumpOnOutOfMemoryError -cp TA.jar com.myClass

You don't need to set them at JAVA_OPTIONS. To be sure that your application is using the parameters that you want:

  • open jvisualvm that comes with java. Just type "jvisualvm" at command line if you have set java correctly at your path.
  • open the vm started to your application.
  • check under "JVM Arguments" in the "Overview" tab.

There should be set your jvm options.

2
  • I have to pass some input paramentes as arguments from the command prompt. so in reality my bat file is java -cp TA.jar com.myClass %1 %2 . In this case where should I place the JVM paramters as per your approach.
    – IS_EV
    Jan 31, 2013 at 20:21
  • you could set it before the -cp. Editing the answer. Jan 31, 2013 at 20:24

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.