我如何在xterm中使用args启动.jar?

问题描述 投票:1回答:2
 if (args.length == 0&&runningFromIntelliJ()==false) {
            String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
            if (OS.indexOf("win") >= 0) {
                String path = CODE.run.class.getProtectionDomain().getCodeSource().getLocation().getPath().substring(1);
                String decodedPath = null;
                try {
                    decodedPath = URLDecoder.decode(path, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                try {
                    Runtime.getRuntime().exec("cmd"+" /c start java -jar \"" + decodedPath + "\" run");
                } catch (IOException e) {
                    e.printStackTrace();
                }
                System.exit(0);
            }
        }
}

此代码在我双击它后在cmd中启动一个程序。问题是它只能在Windows中运行,而我想在树莓派上运行它。现在的问题是,我不知道a如何在xterm中用args启动.jar。

runningFromIntelliJ()只是在测试我是否正在IntelliJ中运行程序,如果执行则跳过该部分。

java args xterm
2个回答
0
投票

似乎在将参数传递给jar时,您的应用程序将不执行任何操作。

if(args.length == 0)

将是假的,因此整个如果。如果您要使用参数运行其他代码,请尝试以下操作:

java -jar yourJar.jar“ arg 1” arg2 @

否则,请检查您的代码。


0
投票

这里是使用xterm启动程序的一种方法。

xterm -hold -e '/bin/bash -c "ls -l"'

在此示例中,程序只是ls命令,但是如何在Java中使用它应该是不言而喻的;只需使用在another answer中找到的示例。

© www.soinside.com 2019 - 2024. All rights reserved.