0

I've inherited some code from a previous developer, which gets built using Ant into an executable jar file that runs by double clicking. The application runs, but under some conditions crashes with an OutOfMemoryError. To investigated this, I'd like to add the -XX:+HeapDumpOnOutOfMemory jvm arg to the Ant buildfile, and as I understand it, the <jvmarg value="-XX:+HeapDumpOnOutOfMemory" /> element needs to go under a <java ...> task. However, there is no <java ...> task to be found in this or any other Ant buildfiles in this code base.

How is this even possible? How can the jar file be executable without a <java ...> task?

I'm asking primarily to find out what in fact makes my jar file executable so that I can figure out where to put that <jvmarg /> element to debug the OOME.

Thanks!

Y.S.
  • 1
  • Please post the build.xml contents. You get quick answers.. – Jayan Jun 23 '12 at 06:13
  • JB Nizet's answer tells the truth. Also, you can write a start script to start your app. A start script is usually a .bat, .cmd(Windows) or .sh(*nix) file, in which you can do environment param checking, define jvm arguments as well as preset start arguments of your app, and so on. For example, you can check Tomcat's catalina.bat or catalina.sh and see what it does. – Dante WWWW Jun 24 '12 at 10:42

2 Answers2

1

A <java> task doesn't create an executable jar file. It executes a Java program.

I don't think it's possible to specify VM parameters when starting an executable jar file by double-clicking on it. If you want to pass VM parameters, open a command prompt and execute the jar this way:

java -XX:+HeapDumpOnOutOfMemory -jar nameOfTheJar.jar
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • See @digitaljoel's answer. And read http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html – JB Nizet Jun 22 '12 at 18:50
1

Your jar is executable because it has a Main-Class defined in the META-INF/MANIFEST.MF file. Double clicking it to run doesn't do anything with Ant. Ant is simply used to package the jar.

In order to add the parameter and still launch via a double click you could create a shortcut that runs the command in JB Nizet's answer

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
digitaljoel
  • 26,265
  • 15
  • 89
  • 115