6

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.

1
  • 4
    I have a script in ~/bin/ that contains just scala -cp target/classes:`mvn dependency:build-classpath | grep "^[^\[]"` for use with Scala-pluginless Maven projects. Commented Aug 11, 2012 at 16:01

2 Answers 2

3

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.

1

This question is primarily about build systems and the potential complexity of persuading an existing build system to incorporate a REPL. One of the things that I love about both sbt and Leiningen is that they both provide REPL support out of the box. Unfortunately moving an existing project from Ant/Maven/whatever to one of these might not be straightforward.

But if your existing project already publishes to a Maven or Ivy repository (or could be persuaded to do so easily enough) then you can create a new sbt or Leiningen project, import the artefacts published by your existing project, and you're done...

1
  • I'm also looking for solutions that exist outside of a build tool. sbt, lein, and mvn all provide a REPL, but ant, gradle, and make do not. Commented Aug 11, 2012 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.