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

}
12
  • 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. Commented Dec 7, 2018 at 17:00
  • @VGR Sure. I updated it. Thank you. Commented Dec 7, 2018 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: {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. Commented Dec 7, 2018 at 18:05
  • 1
    Actually, after reading the official documentation, I’m not sure. It does say it takes “arguments,” so I’m not sure what the proper usage is. Commented Dec 7, 2018 at 21:05
  • 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. Commented Dec 10, 2018 at 15:16

1 Answer 1

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"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.