12

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.

Emmanuel Bourg
  • 9,601
  • 3
  • 48
  • 76
KarolDepka
  • 8,318
  • 10
  • 45
  • 58
  • I know, that I could also use properties: -J-Dexample_property=value But the app, that I'm launching via webstart expects command line args, not properties. – KarolDepka Sep 08 '09 at 21:41
  • i also need to do something similar (specifying start-up files via args) and have been looking into possibilities using JNLP files, `extenstion` and `component-desc` to be more precise. But I am not sure if it's possible. How do you intend to use `javaws [opts] jnlpfile` even if it's possible to solve the problem that way? – posdef Oct 27 '10 at 11:28

3 Answers3

6

There is nothing to confuse. The very straight answer which I tested and it is working perrfect.

To send the command line argument to any JNLP is very simple.

command prompt > javaws -open space arg1 space arg2 ... space arg n JNLP url

Ex:

c:\>javaws -open arg1 arg2 arg3 c:\myjnlp.jnlp

But remember one thing, We can get the -open also as args[0] in main method, so just avoid args[0]. Also it is not possible to avoid -open with direct argument prepixed with -.

assylias
  • 321,522
  • 82
  • 660
  • 783
  • Confirmed. I'm using this for about a year already. Thanks for response. – KarolDepka Mar 26 '11 at 09:42
  • @KarolDepka, can you please help me with this question? - https://stackoverflow.com/questions/48646134/how-to-use-variables-in-jnlp-arguments – thathashd Feb 08 '18 at 10:02
  • Can I use the -open switch also to pass values to the argument? – thathashd Feb 08 '18 at 10:03
  • I seem to be unable to get this to work. I am not sure if the syntax is incorrect or what when I put in "javaws myJNLP" it runs the java app, when i uses "javaws -open arg arg arg myJNLP" it says it can't find the jnlp file. Can anyone help? – Tacitus86 Dec 07 '18 at 16:41
  • Further comment: I found that it works for a single arg but doesn't seem to work for more than one. Has anyone gotten this to work with multiple args? – Tacitus86 Dec 10 '18 at 15:13
3

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.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Guss
  • 30,470
  • 17
  • 104
  • 128
  • 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 ? – KarolDepka Sep 09 '09 at 13:53
  • -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. – KarolDepka Sep 09 '09 at 14:05
  • 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 Sep 09 '09 at 18:27
  • 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? – KarolDepka Sep 09 '09 at 18:37
  • 1
    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 Sep 09 '09 at 18:55
  • That's a weird and avoidable incompatibility, don't you think? – KarolDepka Sep 09 '09 at 18:59
  • 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 Sep 09 '09 at 19:29
  • 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 :
    -open If specified, replaces the arguments in the jnlp file with -open .
    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.
    – KarolDepka Sep 09 '09 at 20:38
  • 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. – KarolDepka Sep 09 '09 at 20:49
  • I think they meant that -open 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 Sep 10 '09 at 08:54
  • 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). – KarolDepka Sep 10 '09 at 09:54
  • 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 Sep 10 '09 at 10:29
2

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
  • 21
  • 1
  • Would not work if you are online. I am now using -open myarg and it works for the use case that i need. – KarolDepka Oct 30 '10 at 19:04
  • 1
    what is codewriter, mentioned in your answer. Can you please explain a bit more on how to generate dynamic jnlp. – Harshdeep Jun 14 '12 at 18:28