Command line arguments in jar files

My jar’ed app needs more than the default maximum heap size of 64 megs.

How do I:

  1. Run the jar’ed application deployed via webstart specifying the minimum and maximum heap sizes allocated similar to the effect achieved with this command line “java -Xms64m -Xmx128m MyClass”?

Thanks :slight_smile:

Something like:

in your JNLP will sort you out.

Kev

Thanks for the answer :slight_smile:

I’ve got the same question but without the Webstart option. :slight_smile:
Ie: I’ve got one startable JAR file which however needs more than 64 M.

I guess it’s impossible to tell “inside” a JAR the max memory size (because the VM is already running…) ?

However I’d need right that. I don’t use two JARs. Maybe there’s some trick? A class inside the one JAR could start another class inside the same JAR but with a new and larger memory VM …?

I believe you’d need to start up a second VM from inside the first with a the appropriate settings.

However, if you know for sure you’re running from the shell/OS then you could just add a script file .bat/.sh whatever which sets the appropriate settings.

Or you could consider this, which I find quite nice:

http://jsmooth.sourceforge.net/

Kev

[quote]I believe you’d need to start up a second VM from inside the first with a the appropriate settings.
[/quote]
Yes, indeed.
Something like…[quote]
Process p = Runtime.getRuntime().exec(“java -Xmx128M -jar Jarfilename.jar -secondstart”);
[/quote]
… works (by querying the param I see if it’s already the second invocation with lots of RAM). Although it looks a little bit like overkill to me.

Is there a nice way to find out the name of the JAR from within which “I” am running?
Being at that, is it possible to see if “I” am being called from outside a JAR, ie from class files lying inside a “normal” folder?

[quote]However, if you know for sure you’re running from the shell/OS then you could just add a script file .bat/.sh whatever which sets the appropriate settings.
[/quote]
Yes, I’m aware of this but tried to avoid if possible (it is, as I see now).

[quote]Or you could consider this, which I find quite nice:
[/quote]
I’m happy not to use Exes. :wink:

Thanks for your hints.

If you use

URL me = getResource(“myclassnamehere”);

The URL should contain the name of the jar file (if any). Infact some the accessors on URL can probably be used to pull it out.

Kev

Don’t use the “-secondstart” argument. Just query the size of the heap at runtime. If it is enough then you don’t need to start a second instance with the memory params specified.

Why are you against a launcher stub (exe)?? After all that’s what java.exe is :). Perhaps you should consider WebStart?

[quote]Don’t use the “-secondstart” argument. Just query the size of the heap at runtime. If it is enough then you don’t need to start a second instance with the memory params specified.
[/quote]
Another good idea. Thanks for the input.

[quote]Why are you against a launcher stub (exe)??
[/quote]
You as a Mac user are asking me this? Lol.
I love pure Java apps, no exe, no nothing. Virtual byte code rules. Compiled native code is nonflexible and ancient. :slight_smile:

[quote]After all that’s what java.exe is :slight_smile:
[/quote]
But this belongs to the JVM which has to be installed anway. However my app should run on any Java enabled platform unmodified.

[quote]Perhaps you should consider WebStart?
[/quote]
For a game, well yes, maybe.
For game tools I prefer one clickable JAR.

@Kev: smart idea, thanks.

[quote]Something like… Quote:

Process p = Runtime.getRuntime().exec(“java -Xmx128M -jar Jarfilename.jar -secondstart”);

… works (by querying the param I see if it’s already the second invocation with lots of RAM). Although it looks a little bit like overkill to me.
[/quote]
It would kind of work, provided that doubleclicking a jar works at all!
On my system, it opens power-archiver and I prefer my system like that.
My advice is to simply not depend on a jar being executable by itself and provide start scripts. Or even better, jws of course :).

Na, thats not right is it? The double clicking on a jar is a file association not a command line switch.

If you run "java -jar " explcitly it will always work. Running the java.exe isn’t about to start up power-archiver.

Kev

That’s not what I meant.
My point is that you can’t depend on having the file association and therefor you can’t depend on the jar file being double-clickable in the first place. So the code might work, but you might have to run the program manually anyway, making the extra code to start another jvm a bit pointless…

When a user installs J2SE (JRE), it does make a JAR double-clickable.
So when somebody tells me he can’t double-click my JAR, I’ll tell him to re-install Java.
If this also doesn’t work, I’ll tell him to re-install Winblows. :wink:

Delivering some mini starter script file (.bat and .sh) is still a good additional option, I agree.

[quote]When a user installs J2SE (JRE), it does make a JAR double-clickable.
[/quote]
Is this a part of the java standard or is this a Sun specific implementation thing? I think it’s the latter which means your suggestion to re-install things would not be a very good one (I seem to remember the IBM jre installation not to make the file association, but I’m not sure)

Doh! Sorry, read it wrong. Thought it was a bit of a large oversight :slight_smile:

Kev

Good question. Unfortunately I don’t know.

These are things… With M$-Dotnet they wrap their bytecode within an Exe which then calls via native code the VM… (Another reason I love pure Java files like JAR: no contamination with native code.)

But well, I’ll give my JAR with a starter script (.bat / .sh) to my friends and in case the JAR isn’t double clickable I’ll tell them to double click the .bat … (Hey presto: what if some Powerarchiver steals that extension, hehe…)

[quote] (Hey presto: what if some Powerarchiver steals that extension, hehe…)
[/quote]
Hey, file associations are meant to be stolen :slight_smile:

As a Mac user I expect to have an Application Bundle.
As a Windows user I expect to start an .exe file
As a Linux user I expect to spend several days reconfiguring my system and compiling from source to get something that almost works. :smiley:

Seriously though. Platform independant code is all wonderful, but user experience counts for something too. Windows users don’t expect .jars to be programs. Only Java programmers know that. Get WebStart to make a proper shortcut for you that hides this detail, or use a cross-platform installer such as InstallAnywhere which will make the appropriate launcher for you.

Don’t use InstallAnywhere for a Mac version though. It packages Java apps on a Mac in a very non-Mac way instead of simply making an Application Bundle like you are supposed to on the Mac.

You can make a Mac application bundle on Linux or a PC, you just need a copy of the JavaApplicationStub. I do this on Windows all the time.