将命令行参数传递给 javaws (Java WebStart) 可执行文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1396426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 11:38:53  来源:igfitidea点击:

Passing command line arguments to javaws (Java WebStart) executable

javacommand-linejava-web-start

提问by KarolDepka

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.

我该怎么做呢: ?如果我们可以将 ad-hoc 命令行参数传递给 javaws,那么 javaws 应用程序可能更像是“一等公民”“普通应用程序”。例如,我们可以传递要打开的文件的文件名。

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:

我想知道是否有办法将“ad-hoc”命令行参数传递给 javaws 可执行文件。我已经知道如何在 JNLP 文件中指定它们:

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

但是我认为“这里有一些 CLI 参数”被忽略了。

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.

如果我们可以将 ad-hoc 命令行参数传递给 javaws,那么 javaws 应用程序可能更像是“一等公民”“普通应用程序”。例如,我们可以传递要打开的文件的文件名。像例如

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

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

在 JNLP 中硬编码参数不能满足这个用例。

采纳答案by sunil choudhury

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.

将命令行参数发送到任何 JNLP 非常简单。

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

命令提示符 > javaws -open space arg1 space arg2 ... space arg n JNLP url

Ex:

前任:

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

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

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

但是请记住一件事,我们可以-openargs[0]在 main 方法中一样获取also ,因此只需避免args[0]. 也无法避免-open使用前缀为 的直接参数-

回答by Guss

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.

javaws 可执行文件接受一个运行选项-arg <argument>,它允许被调用者向应用程序发送参数。我认为这些附加到 jnlp 文件中的参数。

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

编辑:上述解决方案仅适用于接受-arg参数的OpenJDK 的 javaws 。根据这篇博文,另一种选择是您可以使用 URL 查询字符串参数将参数传递给 JNLP 文件。这显然只有在您javaws使用完整 URL执行时才有效,如果您将其作为下载链接访问则无效。我没有测试过这个,所以它可能会也可能不会。

回答by Matthew

dynamically generate the webstart jnlp file with the parameters.

动态生成带有参数的 webstart jnlp 文件。

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

$ javaws [选项] 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

codewriter捕获查询参数并从参数中写出动态jnlp