Java Webstart "javaws -open" 标志不适用于多个参数
Java Webstart "javaws -open" flag doesn't work with multiple arguments
我正在尝试调用 Java Webstart,它使用“-open”运行 时间选项向 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);
}
}
这可能是一个丑陋的答案,但由于这个问题还没有任何正确的答案,我将向您展示我的解决方法。将参数作为环境变量传递到 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"))
我正在尝试调用 Java Webstart,它使用“-open”运行 时间选项向 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);
}
}
这可能是一个丑陋的答案,但由于这个问题还没有任何正确的答案,我将向您展示我的解决方法。将参数作为环境变量传递到 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"))