19

I am looking for libraries for Java that will allow me to create an interactive shell. I have done some search around and have not turned up a whole lot. Most of what I have found is libraries for adding command argument parsing to my application which does not help me a lot.

The best lead I have found is a library called Cliche which does exactly what I need. The problem is its too simple. I am looking for something that has more customization.

Has anyone come across something a little more advanced?

AtomicPorkchop
  • 2,625
  • 5
  • 36
  • 55
  • If you are really into customization, you may want to have a look at parboiled. – fge Dec 29 '12 at 10:42

3 Answers3

10

Options to consider:

  • javacurses / JCurses - a console-based windowing toolkit, similar to the UNIX curses design
  • swing-console might be appropriate if you want a console-style view / output in a Swing GUI window. you could use this to build an interactive shell.
  • JLine - library for console input similar to GNU readline
  • Several JVM languages offer an interactive REPL environment which can be used as an interactive shell, e.g. Clojure
mikera
  • 105,238
  • 25
  • 256
  • 415
  • My previous run ins with Curses in other languages proved to be a huge pain for me. But for me to get the functionality I am looking for I may have to consider it as an option. – AtomicPorkchop Dec 29 '12 at 10:23
  • 2
    http://www.beanshell.org/ adds a nice interactive environment, too. – 9000 Dec 29 '12 at 10:26
  • As far what I read about Beanshell that seems like overkill. Its a full blown scripting to language for Java. – AtomicPorkchop Dec 29 '12 at 10:32
7

We are using Spring shell, and it worked really well for us. Some of its features:

  • A simple, annotation driven, programming model to contribute custom commands

  • Use of Spring's classpath scanning functionality asthe basis for a
    command plugin strategy and command develoment

  • Inheritance of the Roo Shell features, most notably tab completion, colorization, and script execution.

  • Customization of command prompt, banner, shell history file name.

Gonzalo
  • 81
  • 1
  • 1
  • In theory a nice library but a small not for future readers: Spring shell is inactive and thus won't get any updates. – derteufelqwe Apr 02 '21 at 11:32
5

According to this Question JLine can be a good try.

Features of JLine

  • Command history - Lines that have been previously entered may be recalled and edited and can be persisted so that they are available
    across sessions of your program.
  • Line editing - JLine allows full editing of the current command line and attempts to mimic as much of the behavior of GNU Readline as possible, including support for both emacs and vi key mappings.
  • Completion - JLine provides a pluggable mechanism for implementing command line tab completion (of course completion can be bound to any key you wish).
  • Custom Key bindings - Keys may be arbitrarily remapped to perform a specific action, and JLine attempts to honor any mapping that is set in your existing readline .inputrc file.
  • Character Masking - Input may be gathered from the user without any visual feedback. This is useful for prompting for passwords.
  • 99.99% Java - The vast portion of JLine is all Java, using only some small bit of native code, provided by the Jansi project, to
    support Windows.
Community
  • 1
  • 1
burna
  • 2,932
  • 18
  • 27
  • 2
    Based on what I was reading JLine looks like it would work well. The problem is the documentation seems to very scarce for the library. Also not as much of a concern but I can't seem to find any example of JLine being used. – AtomicPorkchop Dec 29 '12 at 10:13
  • You can see an Example in the source https://github.com/jline/jline2/blob/master/src/test/java/jline/example/Example.java – burna Dec 29 '12 at 11:43
  • The example they have does not seem to work. Instead of giving me a prompt it just runs and stops. I think Jline will work for me if I can get in touch with the devs and get some more info on how to use it. They don't seem to have a JavaDoc for JLine2 but there is one for Jline1. Thanks for the help. – AtomicPorkchop Dec 30 '12 at 10:33