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.

Community
  • 1
  • 1
Bobby Norton
  • 1,494
  • 11
  • 23
  • 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. – Travis Brown Aug 11 '12 at 16:01

2 Answers2

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.

Community
  • 1
  • 1
Bobby Norton
  • 1,494
  • 11
  • 23
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...

Paul Butcher
  • 10,722
  • 3
  • 40
  • 44
  • 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. – Bobby Norton Aug 11 '12 at 18:04