tags:

views:

53

answers:

4

Hi, My executable swing client throws out of memory exception when executed from a remote machine. However, executing the client from command line (increasing the heap space) using the following command works.

java -XMx128m -Xms128m -jar myclient.jar

I do not want the remote users use my client through command line as shown above. So, can I set this heap space while building the executable? I am using Eclipse's Fat Jar Plug-In to create my executable jar.

Also, is there a way to setup a default value for java heap space for client machines(Windows/Mac/Linux)?

Thanks.

+2  A: 

While I do not know of a way to set a default in the individual OS, I can tell you that the command line is the only place for the -X commands to go. The way we got around that on our project was to give them an installer for windows, or to build them scripts for a particular operating system. For the installer, we used NSIS, which seemed to work really well.

aperkins
+2  A: 

I don't think there is a standard way to specify memory settings from within the application; java needs to start up with the correct settings. The jar file, with manifest, is loaded by java, which has started by then.

You could however use an installer, see this SO question which suggests NCIS. You can also go for a link (on windows) or a bat file / shell script on Windows. Or perhaps the kind of starter Nexus uses. I did some googling and found JSW.

So, in summary, your options seem to be:

  • an installer like NCIS
  • a wrapper like JSW
  • shell script and bat file
  • a link file or some such (conceptually similar to script/bat file)

I think I would start with looking at JSW as some well-known software like Nexus seems to use that. I don't know whether it works well with desktop apps though. But try and and you'll find out :)

extraneon
InstallAnywhere.
Dave Jarvis
+2  A: 

you could also use a wrapper like launch4j which will make an executable for most OS:es and allows you to specify VM options

Faisal Feroz
Looks like a good cross-platform solution.
trashgod
+2  A: 

Mac OS X: The articles Bringing your Java Application to Mac OS X Part 1, Part 2 and Part 3 illustrate how to embed a JAR in a Mac OS application bundle. You can specify run time parameters in the application's property list Info.plist, as discussed in Java Info.plist Key Reference for Mac OS X.

trashgod
Wow, I did not know that information - thanks for that!
aperkins
trashgod
@trashgod: it's funny, because I knew that, I had just never thought about doing it that way. Amazing how the brain misses those obvious connections sometimes.
aperkins