Java Webstart“ javaws -open”标志不适用于多个参数

时间:2018-12-07 16:49:30

标签: java java-web-start java-ws

我正在尝试使用“ -open”运行时选项向Java Webstart进行调用,以将参数发送到Webstart应用程序。我已经参考了问题:Passing command line arguments to javaws (Java WebStart) executable,但是此语法似乎不适用于多个参数。似乎可以找到单个参数。

当我运行“ javaws URLtoMyJNLP”时,它可以很好地运行应用程序,而且当我通过“ javaws -open arg URLtoMyJNLP”发送单个参数时,它也似乎可以正常工作,并且arg进入了应用程序。当我尝试运行“ javaws -open arg arg arg URLtoMyJNLP”时,它说提供了无效的参数。我将命令输入到ProcessBuilder.command中。

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

对于上述输出,我尝试发送“ javaws -open abc 123 hello launch.jnlp”

有什么想法吗?

根据要求输入代码。由于是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);
    }

}

1 个答案:

答案 0 :(得分:4)

这可能是一个丑陋的答案,但是由于没有适当的答案,我将向您展示我的工作。将参数作为环境变量传递到JVM。这将需要编辑源应用程序以查找环境变量以替代参数,但这是解决此Webstart问题的唯一方法,我发现它甚至可以远程运行。

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

在JAR应用程序内部:

    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"))