简体   繁体   English

Java是否有类似Python的交互式控制台?

[英]Is there any Python-like interactive console for Java?

I spent a lot of time programming in Java recently, and one thing I miss from scripting languages was the ability to test them in a console. 我最近在Java中花了很多时间编程,而我从脚本语言中遗漏的一件事就是能够在控制台中测试它们。

To quickly test a java program, I have to edit a file, then turn it to bytecode and execute it. 要快速测试java程序,我必须编辑一个文件,然后将其转换为字节码并执行它。 Even using an IDE, it loses its fun after the 372 th time. 即使使用IDE,它在第372次之后也会失去乐趣。

I would like to know if there is a product out there that features anything like an interactive console (I bet you need a JIT compiler) and some autocompletion (with relexivity, I suppose it's possible). 我想知道是否有一个产品,其中包括交互式控制台(我打赌你需要一个JIT编译器)和一些自动完成(具有反复性,我认为它是可能的)。

Maybe that's something very common that I just don't know about or something completely impossible, but its worst asking :-) 也许这是我不知道的非常普遍的东西或者完全不可能的东西,但最糟糕的是:-)

Yes; 是; jshell , and before that some close approximations are Groovy , Clojure , Scala , and the Bean Shell . jshell ,在此之前,一些近似的东西是GroovyClojureScalaBean Shell

Funnily enough, you get an interactive console with Jython ! 有趣的是,你可以通过Jython获得一个交互式控制台! You don't get much more Python-like. 你没有得到更多的Python等。

Java REPL http://www.javarepl.com/term.html Java REPL http://www.javarepl.com/term.html

with an intellij plugin: http://plugins.jetbrains.com/plugin/7215?pr= 使用intellij插件: http ://plugins.jetbrains.com/plugin/7215?pr =

试试Java博士的 “交互窗格”。

JShell现在是Java 9的标准.JShell简介

An approach that I have used to some degree of success is to debug in Eclipse and use the display view. 我在某种程度上取得了成功的方法是在Eclipse中进行调试并使用显示视图。 What the display view gives you is the ability to manipulate the code currently running in the JVM through executing Java statements. 显示视图为您提供的是通过执行Java语句来操作当前在JVM中运行的代码的能力。 Any object available at the particular break point you are stopped at is in scope within the display view. 在您停止的特定断点处可用的任何对象都在显示视图中的范围内。 While this isn't exactly what you are looking for it does provide some of the features that a REPL provides for other programming environments. 虽然这不是您正在寻找的,但它确实提供了REPL为其他编程环境提供的一些功能。 See Debugging with the Eclipse Platform for more information. 有关更多信息,请参阅使用Eclipse Platform进行调试

您也可以执行Scala交互式解释器。

You can use BeanShell to run arbitrary Java code. 您可以使用BeanShell运行任意Java代码。 If you want Eclipse integration, EclipseShell has BeanShell support. 如果您想要Eclipse集成, EclipseShell可以支持BeanShell。

您可能对Groovy感兴趣。

Jgrasp IDE have a interactive console where you can test in, i use it a lot, and there is alos a debug view showing variabel etc efter you have deklare them. Jgrasp IDE有一个交互式控制台,你可以在其中进行测试,我经常使用它,还有一个调试视图显示变量等等,然后你就可以了解它们。

It is opensoruce and you can get a copy att http://www.jgrasp.org/ 这是opensoruce,你可以得到一份副本http://www.jgrasp.org/

// Anders //安德斯

I've occasionally run into the same problem and have a partial solution. 我偶尔遇到同样的问题,并有一个部分解决方案。 I keep around a file (as Charlie Martin said, Java needs its class contexts) that is little more than a test program. 我保留一个文件(正如Charlie Martin所说,Java需要它的类上下文),这只不过是一个测试程序。 In a second window - a console - I have a script that I run that just checks the modification time of the source file every second or two. 在第二个窗口 - 控制台 - 我运行的脚本只是每两秒或两次检查一次源文件的修改时间。 When it sees the source change, it re-compiles it (I'm usually fiddling in C, but I've done this with Java, as well) and executes the result. 当它看到源更改时,它重新编译它(我通常在C中摆弄,但我也用Java做过)并执行结果。

It's not a great solution, but its a fast one-off and I've found it to be very useful. 这不是一个很好的解决方案,但它是一个快速的一次性,我发现它非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM