如何在 JNLP 参数中使用变量 [英] How to use variables in JNLP arguments

查看:18
本文介绍了如何在 JNLP 参数中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有以下示例 jnlp:

Having the following sample jnlp:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="$$codebase" href="$$name">
    <information>
        <title>Some Example</title>
        <vendor>Some Sample Vendor</vendor>
        <homepage href="http://www.somesamplevendorhomepage.com"/>
        <description>Some Sample Description</description>
        <icon kind="splash" href="link_to_some_splash.jpg"/>
        <offline-allowed/>
    </information>
    <security>
        <all-permissions/>
    </security>
    <update check="always" policy="always"/> 
    <application-desc main-class="com.some.sample.Main">
        <argument>--URL=SAMPLE_DB_NAME=http://localhost:<db_port>/webapplication/creds/auth</argument>
        <argument>--UserTimeout=350</argument> 
    </application-desc>
    <resources>
        <j2se version="1.7+" />
        <jar href="com.some.sample_1.0.0.jar"/>
        .
        .
        .
    </resources>
</jnlp>

(请忽略格式或其他不一致之处——唯一重要的部分是参数部分)

(please ignore formatting or other inconsistencies - the only part that matters is the argument part)

argument 标记中具有变量 db_port,是否可以在使用 javaws 执行 jnlp 时将值传递给该变量?

Having the variable db_port within the argument tag, is there a way to pass a value to this variable when executing the jnlp with javaws?

例如:javaws/path/to/sample.jnlp 31022

JNLP 将 JAR 下载到位于(在 Windows 上)AppData\LocalLow\Sun\Java\Deployment\cache 下的缓存文件夹.有没有办法使用下载的 JAR(我的应用程序有多个 JAR 文件)以便有一种方法来执行直接向下载的 JAR 提供参数的应用程序?

JNLP downloads the JARs to the cache folder located (on Windows) under AppData\LocalLow\Sun\Java\Deployment\cache. Is there a way to use the download JARs (my app has multiple JAR files) in order to have a way to execute the app providing the argument directly to the downloaded JAR?

例如:

jar -jar app.jar --URL=SAMPLE_DB_NAME=http://localhost:<db_port>/webapplication/creds/auth

<小时>

PS:我知道存储在缓存文件夹中的文件具有计算生成的名称,并且它们没有 .jar 扩展名.但是,从 Java 控制面板 GUI 或带有javaws -viewer"的 CMD/PS,我能够确定用作 jnlp 的文件并启动它.我想知道是否有一种方法可以使用某些 JAR 来启动应用程序,或者创建一个父"应用程序以便能够将参数传递给它.


PS: I understand that the files that are stored in the cache folder have a computed generated name and they are without the .jar extension. However from the Java Control Panel GUI or from CMD/PS with "javaws -viewer" I was able to determine the file used as jnlp and launch it. I was wondering if there is a way to use some of the JARs to launch the app or maybe create a "parent" one in order to be able to pass arguments to it.

推荐答案

文档好像是 故意缺少这个话题,但是文档建议 将命令行参数传递给 javaws 可执行文件的首选方法是通过 -userConfig 标志.

The documentation seems to be intentionally lacking on this topic, but the documentation suggests the preferred method to pass command line parameters to the javaws executable is through ‑userConfig flag.

例如

javaws /path/to/sample.jnlp -userConfig port 31022

文档没有为此提供示例.我什至在 GitHub 上搜索了 javaws userConfig 并且只得到了一个 少数结果,所以这似乎是一个很少使用的功能.

The documentation doesn't provide examples for this. I even searched GitHub for javaws userConfig and only got a handful of results, so this seems to be a very rarely used feature.

由于您的问题专门询问包含在另一个变量中的 变量,因此这不是直接支持的.假设您可以访问源代码,您需要找到一种方法来使用附加变量和主类中的一些搜索/替换来通配符或参数化 <port>.如果您无权访问源代码,您将无法手动编写 JNLP,如果它是 签名文件.

Since your question specifically asks about a <port> variable contained within another variable, that is not something directly supported. You would instead need to find a way to wildcard or paramaterize the <port> using an additional variable and some search/replace inside the main class, assuming you have access to the source. If you don't have access to the source, you will be stuck writing the JNLP by hand, which can have additional work required if it's a signed file.

这篇关于如何在 JNLP 参数中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆