What techniques that people have found useful using Clojure, Scala, JRuby, build tools, etc. to retrofit a Java project with a REPL to quickly experiment?
I often need to work with plain old Java projects (POJO projects?) and miss having a REPL. Other SO questions address this topic, but these are several years old and the responses are dated.
I'll start by contributing a few techniques that I've used to solve this problem.
Creating Team ProjectsFrom your team dashboard, create a new project. Select project language, title, description, due date, and whether this will be a group project. You'll be redirected to the IDE to add any comments, tests, and initial coding blocks you'd like your students to start from.
The Java Shell tool (JShell) is an interactive tool for learning the Java programming language and prototyping Java code. JShell is a Read-Evaluate-Print Loop (REPL), which evaluates declarations, statements, and expressions as they are entered and immediately shows the results.
Running code from replit.com's REPL You can type code in the right-hand pane (pane 3) and press the “Enter” key to run it.
If the project uses Maven, the gmaven plugin and accompanying mvn groovy:shell
is helpful, although getting it configured correctly can be challenging.
For those projects not using Maven, a common pattern is to include dependencies in a lib folder and manage them manually. For these, I've used groovy:
groovysh -cp `echo lib/*.jar | sed 's/ /:/g'`
...or clojure:
java -cp /usr/local/Cellar/clojure/1.3.0/clojure-1.3.0.jar:`echo lib/*.jar | sed 's/ /:/g'` clojure.main
The default Clojure wrapper can also be enhanced with rlwrap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With