How to use JLine in windows?

1,184 views
Skip to first unread message

Ruaan Viljoen

unread,
Aug 26, 2014, 7:03:07 PM8/26/14
to jline...@googlegroups.com
Please, any help or redirection would be greatly appreciated. I have been through hours of wiki, stackoverflow and reading but I don't understand how to get JLine working.
 
I downloaded the last jline 1.0 and added the .jar to my eclipse project, but the ConsoleReader.ReadLine is not blocking, it just reads null in an infinite loop.
 
a) I don't have a Maven project and have no idea how to get Maven working.
b) I don't care about cross platform atm, I just want to get simple input and keyboard intercepts working using JLine.
 

 

Thanks in advance
Current code excerpt:
 
ConsoleReader reader = new ConsoleReader();
reader.setBellEnabled(false);
reader.setDebug(new PrintWriter(new FileWriter("writer.debug", true)));
while ((line = reader.readLine("prompt> ")) != null || true) {
          out.println("======>\"" + line + "\"");
          out.flush();
        }

 

 

 

Andrew McDonald

unread,
Feb 21, 2015, 4:39:42 PM2/21/15
to jline...@googlegroups.com
I am also having trouble with getting jline to work on Windows.

This is also how jline work for me using eclipse.

So I took jline's Example.java and put it in small gradle project.
Running it in a cmd prompt gives me the following.
>.\build\install\jansiExample\bin\jansiExample.bat color
[ERROR] Terminal initialization failed; falling back to unsupported
java.lang.NoClassDefFoundError: Could not initialize class org.fusesource.jansi.internal.Kernel32
        at org.fusesource.jansi.internal.WindowsSupport.getConsoleMode(WindowsSupport.java:50)
        at jline.WindowsTerminal.getConsoleMode(WindowsTerminal.java:204)
        at jline.WindowsTerminal.init(WindowsTerminal.java:82)
        at jline.TerminalFactory.create(TerminalFactory.java:101)
        at jline.TerminalFactory.get(TerminalFactory.java:158)
        at jline.console.ConsoleReader.<init>(ConsoleReader.java:229)
        at jline.console.ConsoleReader.<init>(ConsoleReader.java:221)
        at jline.console.ConsoleReader.<init>(ConsoleReader.java:209)
        at jline.example.Example.main(Example.java:50)

←[1mfoo←[0m@bar←[32m@baz←[0m> quit
←[33m======>←[0m"quit"
[WARN] Task failed
java.lang.NoClassDefFoundError: Could not initialize class org.fusesource.jansi.internal.Kernel32
        at org.fusesource.jansi.internal.WindowsSupport.setConsoleMode(WindowsSupport.java:60)
        at jline.WindowsTerminal.setConsoleMode(WindowsTerminal.java:208)
        at jline.WindowsTerminal.restore(WindowsTerminal.java:95)
        at jline.TerminalSupport$1.run(TerminalSupport.java:52)
        at jline.internal.ShutdownHooks.runTasks(ShutdownHooks.java:66)
        at jline.internal.ShutdownHooks.access$000(ShutdownHooks.java:22)
        at jline.internal.ShutdownHooks$1.run(ShutdownHooks.java:47)

From the http://jline.sourceforge.net/ page my guess is that I have a strict security manager installed on my company's laptop.  The original problem was with grails, it just stop working and returned a StackOverflow exception.  Using grails -debug and eclipse the jline code
WindowsSupport.getConsoleMode() failed.  So some update was applied by the IT folks that is now causing jline to fail :(

So how do I know if my company's laptop has a strict security manager??

The attached code used gradle 2.2.1, just run 'gradle installApp' to create the batch file shown above.

jansiExample.zip

Gunnar Mjöberg

unread,
Aug 20, 2015, 4:04:43 PM8/20/15
to jline-users
Here are my steps, using Gradle.

build.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'

dependencies {
    compile('jline:jline:2.12.1')
}

repositories {
    mavenCentral()
}

task createSetClasspathScripts << {
    File cmd = project.file("set-classpath.cmd")
    File sh = project.file("set-classpath.sh")
    String cp = sourceSets.main.runtimeClasspath.asPath

    cmd.write "set classpath=\"$cp\"\r\n"
    println "wrote " + cmd.canonicalPath
    sh.write "#!/bin/bash\nexport CLASSPATH=\"$cp\"\n"
    sh.setExecutable(true)
    println "wrote " + sh.canonicalPath
}

The task cSCS creates scripts that set the CLASSPATH for both cmd and Cygwin Bash.

In cmd (the Command Prompt window):

path> gradle assemble cSCS

path> set-classpath.cmd

path> java -cp %classpath% java.jline.Example files

(if you have copied https://github.com/jline/jline2/blob/master/src/test/java/jline/example/Example.java to src/main/java/jline/example and removed its color/ansi section)
Reply all
Reply to author
Forward
0 new messages