将命令行参数传递给 javaws (Java WebStart) 可执行文件
对于那些可能不想读那么多的人来说,摘要:
我该怎么做:?如果我们可以将临时命令行参数传递给 javaws,那么 javaws 应用程序可能更像“一等公民”“普通应用程序”。例如,我们可以传递要打开的文件的文件名。
我想知道是否有一种方法可以将“临时”命令行参数传递给 javaws 可执行文件。我已经知道如何在 JNLP 文件中指定它们:
<application-desc main-class="org.example.ClassName">
<argument>...
虽然这可以用于我想要完成的任务,但我将其视为一种解决方法。 我尝试过
javaws http://example.org/launch.jnlp <some CLI args here>
,但我认为“这里的一些 CLI 参数”被忽略了。
如果我们可以将临时命令行参数传递给 javaws,那么 javaws 应用程序可能更像“一等公民”“普通应用程序”。例如,我们可以传递要打开的文件的文件名。 例如,
javaws [options] http://example.org/launch.jnlp my_file.jpg
在 JNLP 中硬编码参数并不能满足此用例。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有什么可混淆的。我测试过的非常直接的答案并且运行完美。
将命令行参数发送到任何 JNLP 非常简单。
命令提示符>
javaws -open space arg1 space arg2 ... space arg n JNLP url
例如:
c:\>javaws -open arg1 arg2 arg3 c:\myjnlp.jnlp
但请记住有一件事,我们可以在 main 方法中将
-open
也作为args[0]
获取,所以只要避免args[0]
即可。此外,也不可能避免使用前缀为-
的直接参数来避免-open
。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 asargs[0]
in main method, so just avoidargs[0]
. Also it is not possible to avoid-open
with direct argument prepixed with-
.javaws 可执行文件接受运行选项
-arg
,它允许被调用者向应用程序发送参数。我认为这些已附加到 jnlp 文件中的参数中。因此,您的调用可能如下所示:
编辑: 上述解决方案仅适用于接受
-arg
参数的 OpenJDK 的 javaws。根据这篇博文,另一种选择是您可以将参数传递给 JNLP使用 URL 查询字符串参数的文件。显然,只有当您使用完整的 URL 执行javaws
时,这才会起作用,而如果您作为下载链接访问它,则不起作用。我还没有测试过这个,所以它可能有效也可能无效。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:
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 executejavaws
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.使用参数动态生成 webstart jnlp 文件。
$ javaws [选项] http://example.org/codewriter/write.jnlp? param1=my_file.jpg
代码编写器捕获查询参数,并从参数中写出动态jnlp
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