问题描述
我有一个提供客户端库的 CMS 服务器.我希望能够从命令行以交互方式驱动 CMS.
I have a CMS server that provides a client library. I'd like to be able to drive the CMS interactively from the command line.
基本方法是:
- 创建与 CMS 的连接
- 将 CMS 连接对象添加到 REPL 上下文
- 将 REPL 连接到 stdout/stderr/stdin
- 启动守护线程以保持 REPL 运行.
我希望我也许可以利用 Groovy 来做到这一点,但没有设法让它发挥作用.
I was hoping that I could perhaps leverage Groovy to do this but haven't managed to get it working.
是否有提供 REPL 支持的库?
你能提供一个简单的例子吗?
推荐答案
我在 Groovy 中得到了这个.
I got this working with Groovy.
public static void main(final String[] args) {
Binding binding = new Binding();
// Configure your bindings here.
Groovysh shell = new Groovysh(binding, new IO());
shell.run(args);
}
已知问题
但是,当应用程序从 Eclipse 启动时(即使用 Eclipse 的控制台"视图),它不会工作.要解决此问题,您必须更新 Eclipse 启动配置以传递以下 VM 参数:-Djline.terminal=jline.UnsupportedTerminal
.
Known Issues
However, it won't work when the app is started from Eclipse (ie using the Eclipse 'console' view). To work around this you must update the Eclipse launch configuration to pass the following VM argument:-Djline.terminal=jline.UnsupportedTerminal
.
这篇关于如何轻松地用 Java 编写 REPL 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!