Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Webstart "javaws -open" flag doesn't work with multiple arguments

Tags:

I'm trying to make a call to Java Webstart that uses the "-open" run time option to send arguments to the webstart application. I have referenced the question: Passing command line arguments to javaws (Java WebStart) executable, but this syntax doesn't seem to work for multiple arguments. It seems to work find for a single argument though.

When i run "javaws URLtoMyJNLP" it runs the application fine, also when I send a single argument by "javaws -open arg URLtoMyJNLP" it also seems to work and the arg gets to the application. When I attempt to run "javaws -open arg arg arg URLtoMyJNLP" it says invalid arguments supplied. I enter the command into ProcessBuilder.command.

InvalidArgumentException[ Invalid arguments supplied: {hello, jnlp, launch.jnlp, 123 }]

For the above output I attempted to send "javaws -open abc 123 hello launch.jnlp"

Any ideas?

Code as requested. It's overly simplistic due to being a PoC.

private static void launchApp(String appName, String appPath, String... args)
{
    logger.debug("Launching application: " + appName);

    Properties props = System.getProperties();
    ArrayList<String> fullCmdString = new ArrayList<String>();

    logger.debug("http://" + System.getProperty("jnlp.serverip") + ":" + System.getProperty("jnlp.serverport") + "/FB2HMI/" + appPath);

    if (args.length > 0)
    {
        fullCmdString.add("javaws");
        fullCmdString.add("-open");
    }
    for (String arg : args)
    {
        fullCmdString.add(arg);
    }

    fullCmdString.add("http://" + System.getProperty("jnlp.serverip") + ":" + System.getProperty("jnlp.serverport") + "/FB2HMI/" + appPath);
    logger.debug("Command = " + fullCmdString);
    ProcessBuilder rmLauncher = new ProcessBuilder().command(fullCmdString.stream().toArray(String[]::new));
    Process p;
    try
    {
        p = rmLauncher.start();

        processList.add(p);
        logProcessOutput(p, logger, null, appName);
    }
    catch (Exception e)
    {
        logger.fatal("Failed to launch " + appName + ": " + e);
        System.exit(1);
    }

}
like image 763
Tacitus86 Avatar asked Dec 07 '18 16:12

Tacitus86


People also ask

Is JNLP deprecated?

Java Applet and WebStart functionality, including the Applet API, The Java plug-in, the Java Applet Viewer, JNLP and Java Web Start including the javaws tool are all deprecated in JDK 9 and will be removed in a future release.


1 Answers

This may be an ugly answer but since there hasn't been any proper answers to this question I will show you my work around. Pass the arguments as environment variables into the JVM. This will require editing of the source application to look for environment variables as an alternative to arguments, but it is the only way around this webstart issue that I have found that even remotely works.

Map<String, String> saArgs = new HashMap<String, String>();
saArgs.put("jnlp.serverip", System.getProperty("jnlp.serverip"));
saArgs.put("jnlp.serverport", System.getProperty("jnlp.serverport"));
saArgs.put("port", "8887");
saArgs.put("surfaceip", "192.168.0.50");

ProcessBuilder rmLauncher = new ProcessBuilder().command(fullCmdString.stream().toArray(String[]::new));
    Process p;

    for (Map.Entry<String, String> entry : args.entrySet())
    {
        rmLauncher.environment().put(entry.getKey(), entry.getValue());
    }

    try
    {
        p = rmLauncher.start();
     }
    catch (Exception e)
    {
        logger.fatal("Failed to launch " + appName + ": " + e);
        System.exit(1);
    }

Inside the JAR application:

    logger.debug("jnlp.serverip = " + env.get("jnlp.serverip"));
    logger.debug("jnlp.serverport = " + env.get("jnlp.serverport"));
    logger.debug("port = " + env.get("port"));
    logger.debug("surfaceip = " + env.get("surfaceip"))
like image 135
Tacitus86 Avatar answered Oct 23 '22 11:10

Tacitus86