简体   繁体   中英

Passing command line arguments to javaws (Java WebStart) executable

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". Eg 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". Eg we could pass filenames of files to be opened. Like eg

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

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

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 - .

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM