首页 > 解决方案 > 尝试从 java 运行 jar 时无法获取控制台实例

问题描述

当运行以下执行 jar 并成功退出的代码时,但 jar 不起作用,我得到输出“尝试从 java 运行 jar 时无法获取控制台实例”

       final Runtime re = Runtime.getRuntime();

        final Process command = re.exec("java -jar C:\\dev\\azure-workbench-client\\src\\test\\resources\\azure-file-upload-1.1.1-SNAPSHOT-jar-with-dependencies.jar "+
        "C:\\dev\\azure-workbench-client\\src\\test\\resources\\settings.properties C:\\dev\\azure-workbench-client\\src\\test\\resources\\dummyfile");
        this.error = new BufferedReader(new InputStreamReader(command.getErrorStream()));
        this.op = new BufferedReader(new InputStreamReader(command.getInputStream()));
        // Wait for the application to Finish
        command.waitFor();
        this.exitVal = command.exitValue();
        if (this.exitVal != 0) {
            throw new IOException("Failed to execure jar, " + this.getExecutionLog());
        }
        System.out.println("** " + this.getExecutionLog());

知道是什么原因造成的吗?

标签: javaexecutable-jar

解决方案


原来我正在执行的 jar 试图使用控制台接收输入。

我删除了它并且它有效。


推荐阅读