Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Techniques to add a REPL to a Java project

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.

like image 992
Bobby Norton Avatar asked Aug 11 '12 03:08

Bobby Norton


People also ask

How do I create a project in repl?

Creating Team Projects​From 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.

Does Java have a repl?

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.

How do I run code on repl?

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.


1 Answers

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.

like image 67
Bobby Norton Avatar answered Oct 02 '22 14:10

Bobby Norton