views:

1724

answers:

2

Hi. Summary for those who might not want to read that much:

How do I do this: ? If we could pass ad-hoc command-line args to javaws, then javaws apps could be more like "1st class citizen" "ordinary application". E.g. we could pass filenames of files to be opened.

I would like to know if there is a way to pass "ad-hoc" command line arguments to the javaws executable. I already know how to specify them in JNLP file:

<application-desc main-class="org.example.ClassName">
<argument>...

While this can be used for what i want to accomplish, i treat this as a workaround. I tried

javaws http://example.org/launch.jnlp <some CLI args here>

But "some CLI args here" were just ignored, i think.

If we could pass ad-hoc command-line args to javaws, then javaws apps could be more like "1st class citizen" "ordinary application". E.g. we could pass filenames of files to be opened. Like e.g.

javaws [options] http://example.org/launch.jnlp my_file.jpg

Having arguments hardcoded in JNLP does not satisfy this use case.

+2  A: 

the javaws executable accepts a run-option -arg <argument> which allows the called to send arguments to the application. I think these are appended to the arguments in the jnlp file.

So your call might look like this:

javaws [options] -arg my_file.jpg http://example.org/launch.jnlp

Edit: The above solution only works with OpenJDK's javaws which accepts the -arg parameter. Another option, according to this blog post, is that you can pass arguments to the JNLP file using URL query string parameters. This will obviously only work if you execute javaws with the full URL and won't work if you access it as a download link. I have not tested this so it may or may not work.

Guss
Hi. Thanks for the answer.This doesn't seem to work. javaws just prints general usage info.My javaws version is "Java(TM) Web Start 1.6.0_13".How come the -arg option is not documented in http://java.sun.com/javase/6/docs/technotes/tools/share/javaws.html ?Maybe you meant -open ?
karolrvn
-open could probably satisfy me. But I will need to handle the superfluous "-open" arg in my app, in a special way. Weird, that javaws passes the "-open" to the app.
karolrvn
Interesting. I'm using OpenJDK with IcedTea6 and now that I check its javaws supported options are very different then the javaws shipped with Sun's JDK. If this feature is important to you then maybe you could upgrade to OpenJDK. Possibly this feature will also be in Sun's JDK 7.
Guss
Thanks for clarifying. I'm in a middle of big programming work so i will not upgrade to OpenJDK anytime soon.I'm now using "-open" arg and adapted my app to remove it from String args[]. Is "-open" supported in your JDK version?Also, if I may correct You: "different then"->"different than", i think. Or is this spelling official now?
karolrvn
Yea, I always have problem with "then"<->"than". Its my form of dyslexia ;-) . As far as I can tell, the "special" (and silly) form of argument passing in "-open" and "-print" is not supported under OpenJDK's javaws, though you can always mimic it with `-arg -open -arg something-else`. Also -arg does not replace the arguments in the jnlp but appends to them.
Guss
That's a weird and avoidable incompatibility, don't you think?
karolrvn
Your spelling is very good generally.
karolrvn
Thanks :-). Indeed it is weird (though I think the special "-open" and "-print" are even wierder). I can't find much information about this in the web so I have no idea where this came from. Other then that, I've edited my answer with a more sanctioned approach that may work.
Guss
Geez. It seems, that -open can only take 1 argument. Semi-contrary to http://java.sun.com/javase/6/docs/technotes/tools/share/javaws.html#runoptions : <br>-open <arguments>If specified, replaces the arguments in the jnlp file with -open <arguments>.<br>It says argumentS.Anyway, the -open and -print switches aren't even listed when javaws prints its usage. This is going from weird do ugly and from ugly to evil/stupid.
karolrvn
This is even scarier: The javaws launcher has a set of options that are supported in the current release. However, the options may be removed in a future release. ( http://java.sun.com/javase/6/docs/technotes/tools/share/javaws.html#runoptions ) . But explains the lack of -open in OpenJDK.JDK 6 is so many releases away from the first release which had javaws, and they still didn't figure out how to sanely pass CLI args?!?!? That's just unbelievable to me in general. But completely fits into the sorry state of things with javaws implementation.
karolrvn
I think they meant that -open <args> can accept many arguments when passed in a single arg (do they then split them somehow?), so to pass "-open","1","2" you call `javaws -open "1 2"`. Maybe.
Guss
They are not split when they come to String[] args. These would come as "1 2". That possibly makes sense for opening one file. But there are cases in which an app opens many files at once. Or open a file and specify a switch/mode. Is it so much to ask? Or do I have to split the args on spaces or whatever (not difficult really, but the shell should do it, actually, e.g. because of spaces-in-filenames and escape sequences).
karolrvn
You are right, but you are limited by the javaws CLI. I suggest you try the "arguments in query string" method and if that doesn't work then upgrade your javaws.
Guss
A: 

dynamically generate the webstart jnlp file with the parameters.

$ javaws [options] http://example.org/codewriter/write.jnlp?param1=my_file.jpg

the codewriter captures the query parameter and writes out the dynamic jnlp from the parameter

Matthew
Would not work if you are online. I am now using -open myarg and it works for the use case that i need.
karolrvn