lisak
lisak

Reputation: 21981

Is there an alternative to BeanShell ? Something like javascript or groovy console for Java?

I was wondering if there is some kind of shell that would just listen to user input (with a line buffer) and run in internally from within main method, including jdk on classpath. So that it would look like JavaScript console in browsers or groovy console. It would be handy for testing snippets of code.

One could just write this into the shell and hit return:

Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
    System.out.format("%s=%s%n", envName, env.get(envName));
}

This is what bsh.Interpreter can do. But I find it very hard to use. I cannot move back/left with cursor on the shell line... ^[[D^[[D^[[D .... I can only delete last characters. Not sure if it is OS specific (I'm on linux) but it is very inconvenient...

I mean something in Java language, not Jruby, Jython or Groovy

Upvotes: 5

Views: 2235

Answers (3)

evil otto
evil otto

Reputation: 10582

Run bsh.Interpreter under rlwrap - http://utopia.knoware.nl/~hlub/rlwrap/

rlwrap is a great program that adds readline controls (history recall, line editing, etc) to any command-line program.

Upvotes: 0

davorp
davorp

Reputation: 4236

You can try to use the Beanshell graphical desktop that behaves just like a shell.

Start it with:

java bsh.Console   // runs the graphical desktop

Upvotes: 1

Peter Lawrey
Peter Lawrey

Reputation: 533870

Java text console is very basic with line buffering. This is a feature of Java. You can change the input using JNI, however it is simpler to produce a GUI where you have full control over how you want the input to behave.

Upvotes: 1

Related Questions