JLine3 "Unable to create a system terminal" 构建后

JLine3 "Unable to create a system terminal" after build

我刚刚尝试用 Jansi 实现 JLine,但它总是抛出相同的 UnsupportedOperationException 引用 org.jline.terminal.impl.jansi.JansiSupportImpl#winSysTerminal。检查此方法,只有一个简单的 if 决定此异常。

所以版本号一定是问题所在...为了检查它们,我将检测版本的代码复制到我的源

public static void main(String[] args) throws Exception {

    String v = Ansi.class.getPackage().getImplementationVersion();
    System.out.println(Ansi.class.getPackage());
    if (v != null) {
        Matcher m = Pattern.compile("([0-9]+)\.([0-9]+)([\.-]\S+)?").matcher(v);
        if (m.matches()) {
            System.out.println("Major: " + Integer.parseInt(m.group(1)));
            System.out.println("Minor: " + Integer.parseInt(m.group(2)));
        }
    }

    //System.setProperty("jansi.passthrough", "true");
    AnsiConsole.systemInstall();

    String prompt = Ansi.ansi()
            .eraseScreen()
            .fg(Ansi.Color.BLUE).bold().a("Console")
            .fgBright(Ansi.Color.BLACK).bold().a(" > ")
            .reset().toString();

    Terminal terminal = TerminalBuilder.builder()
            .system(true)
            .dumb(false)
            .encoding(Charset.forName("UTF-8"))
            .name("Terminal")
            .jna(false)
            .jansi(true)
            .build();

    LineReader reader = LineReaderBuilder.builder()
            .terminal(terminal)
            .build();

    String line;

    while ((line = reader.readLine(prompt)) != null) {
        System.out.println(line);
    }

}

结果让我大吃一惊: 虽然它在 IntelliJ 中 returns package org.fusesource.jansi, jansi, version 1.17.1, Major: 1, Minor: 17,但控制台不起作用,因为 intellijs 虚拟控制台,它 returns 只有 package org.fusesource.jansi 当我从命令行 运行 之后建造。这一定是由于 intellij 删除了包含信息的清单造成的。它们无法打包,因为它们与我需要 运行 jar 文件的清单同名。

你们知道任何解决方案或解决方法吗?你如何处理这个异常?或者我有什么失败的地方吗?

您似乎将 Jansi 嵌入到您自己的 jar 中。 如果你,你应该能够破解你的 jar 的 MANIFEST.MF 以包含 Jansi 的相关信息。

Manifest-Version: 1.0
Created-By: peter
...

Name: org/fusesource/jansi/
Implementation-Version: 1.17.1