5

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);
    }

}
Tacitus86
  • 1,314
  • 2
  • 14
  • 36
  • 1
    Edit your question and show the Java code that makes the call. I suspect you are misusing Runtime.exec or ProcessBuilder by passing a single `"javaws -open "` string, instead of separate `"javaws", "-open"` string arguments. – VGR Dec 07 '18 at 17:00
  • @VGR Sure. I updated it. Thank you. – Tacitus86 Dec 07 '18 at 17:27
  • @VGR I updated the code and tried what you suggested and got this exception. Obviously the first item is the JNLP file path and shouldn't be an argument. InvalidArgumentException[ Invalid arguments supplied: {http://192.168.0.50:8080/FB2HMI/SystemApp.jnlp, 192.168.0.50 }]. I am passing a port number and a source IP address as arguments and then the JNLP file URL. – Tacitus86 Dec 07 '18 at 18:05
  • I haven’t used `-open`, but from what I see in the documentation, it appears `-open` expects exactly one argument to follow it. – VGR Dec 07 '18 at 20:51
  • I'm surely hoping that is not the case... At least judging by the linked solution. Or do you mean trying to call -open for each argument? – Tacitus86 Dec 07 '18 at 21:02
  • 1
    Actually, after reading [the official documentation](https://docs.oracle.com/javase/9/tools/javaws.htm#JSWOR728), I’m not sure. It does say it takes “arguments,” so I’m not sure what the proper usage is. – VGR Dec 07 '18 at 21:05
  • Thanks for trying. I have been digging on this for a few days ahd can't find a decent usage for it anywhere! I hope someone that has used it comes along, but honestly with it being a nearly dead technology... I don't have high hopes. – Tacitus86 Dec 07 '18 at 21:06
  • @VGR So it kind of worked but kind of not. I tried "javaws - open var1 - open var2 URL" and my app got the arguments "-open" and "var2". The syntax is definitely screwed up somehow and I'm not quite sure how to get it right. – Tacitus86 Dec 08 '18 at 02:14
  • Did you try with double-quotes, something like `javaws -open "var1 var2"` URL ? – yegodm Dec 10 '18 at 14:52
  • @yegodm Yes, this works but sends them all as a single argument. – Tacitus86 Dec 10 '18 at 15:06
  • An aside: I strongly recommend finding another deployment strategy beyond Java Web Start as it is deprecated and being violently removed from production by Oracle: https://stackoverflow.com/a/47168855/963076 – ryvantage Dec 10 '18 at 15:12
  • 1
    @ryvantage I am aware. We will be redesigning this application in HTML5/Javascript in the future, but for now need a webstart solution for the interim. – Tacitus86 Dec 10 '18 at 15:16

1 Answers1

4

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"))
Tacitus86
  • 1,314
  • 2
  • 14
  • 36