Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcards in jnlp template file

Since the last security changes in Java 7u40, it is required to sign a JNLP file. This can either be done by adding the final JNLP in JNLP-INF/APPLICATION.JNLP, or by providing a template JNLP in JNLP-INF/APPLICATION_TEMPLATE.JNLP in the signed main jar.

The first way works well, but we would like to allow to pass a previously unknown number of runtime arguments to our application.

Therefore, our APPLICATION_TEMPLATE.JNLP looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp codebase="*">
    <information>
        <title>...</title>
        <vendor>...</vendor>
        <description>...</description>
        <offline-allowed />
    </information>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <java version="1.7+" href="http://java.sun.com/products/autodl/j2se" />
        <jar href="launcher/launcher.jar" main="true"/>
        <property name="jnlp...." value="*" />
        <property name="jnlp..." value="*" />
    </resources>
    <application-desc main-class="...">
        *
    </application-desc>
</jnlp>

The problem is the * inside of the application-desc tag.

It is possible to wildcard a fixed number of arguments using multiple argument tags (see code below), but then it is not possible to provide more or less arguments to the application (Java Webstart will no start with an empty argument tag).

    <application-desc main-class="...">
        <argument>*</argument>
        <argument>*</argument>
        <argument>*</argument>
    </application-desc>

Does someone can confirm this problem and/or has a solution for passing a previously undefined number of runtime arguments to the Java application?

Thanks alot!

like image 910
Andy Avatar asked Nov 09 '13 21:11

Andy


People also ask

What file format is JNLP?

The Java Network Launch Protocol (JNLP) file for rich internet applications (RIAs) is an XML file.

How does a JNLP file work?

The JNLP file specifies the name of the main JAR file, the version of Java Runtime Environment software that is required to run the RIA, name and display information, optional packages, runtime parameters, system properties, and so on.

Where is JNLP file located?

Click on Start and select Control Panel from the Settings menu (or click Start and select Control Panel). In the control panel, click Folder Options . In the Folder Options window, click the File Types tab. Locate JNLP under the list of registered file types.


1 Answers

From what I can see after reading the JNLP 7 specification, it appears what you want can't be done. The asterisk can only represent text data, not multiple XML elements.

In your situation, I would make the main method capable of doing its own parsing of a single argument so it can be treated as multiple values, using a custom separator. Something like this:

public static void main(String[] args) {
    if (args.length == 2 && args[0].equals("--args")) {
        args = args[1].split(";;");
    }

    // Continue as normal 
}

This allows the template to contain:

<application-desc main-class="com.example.app.Main">
    <argument>--args</argument>
    <argument>*</argument>
</application-desc>

And your the actual .jnlp file could contain something like:

<application-desc main-class="com.example.app.Main">
    <argument>--args</argument>
    <argument>files.txt;;29;;true;;1384212567908</argument>
</application-desc>
like image 141
VGR Avatar answered Oct 02 '22 01:10

VGR