How to use variables in JNLP arguments
Asked Answered
J

1

0

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)

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?

For example: javaws /path/to/sample.jnlp 31022


EDIT:

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?

For example:

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

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.

Juanjuana answered 6/2, 2018 at 15:9 Comment(2)
Possible duplicate of How to use JNLP to pass command line arguments to the application?Jenelljenelle
Although the question seems similar... there is a main difference - I'm asking if there is a way to pass a value to a variable (in this case db_port) the is defined inside the argument tag.Juanjuana
C
0

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.

e.g.

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

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.

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.

Cryptozoic answered 6/2, 2018 at 19:10 Comment(5)
looks like -userConfig switch is used for specific deployment properties.Juanjuana
I was wondering if after downloading to the java cache all the required jars for the application, maybe it is possible to execute locally the app through the main Jar. I will give it a try.Juanjuana
It should be possible and then you would be able to call the main class directly.Cryptozoic
The problem is that the files are stored in different folders and with computed generated names. I'm not sure if it is possible to organize all of them into a single directory and create a zip file with them... and also a MANIFEST file.Juanjuana
I'm not sure how to, but a colleague of mine used a local cache directory to snag them successfully.Cryptozoic

© 2022 - 2024 — McMap. All rights reserved.