27

I have a java web application running under tomcat in a Sun java 6 JVM. Is there a way to attach a scala or clojure REPL to the running JVM ?

Once the webapp is up and running, the context in which the calls are to be made is already setup in the running VM. Hence, this can be really helpful in invoking arbitrary java method calls for incremental, exploratory development and for debugging.

letronje
  • 9,002
  • 9
  • 45
  • 53

4 Answers4

22

Copied over the answer from the other question as per your request:

liverepl: Connect a Clojure REPL to running Java or Clojure processes without any special setup

From the website: Start a Clojure REPL connected to any running Java or Clojure process without needing the process to be setup in any special way beforehand. Now supports connecting to Tomcat web applications. You can use the repl to run code, inspect variables, and redefine Clojure functions.

https://github.com/djpowell/liverepl

Michael Kohl
  • 66,324
  • 14
  • 138
  • 158
7

There's no way to attach a REPL to an already-running JVM, so you need to think about the problem backwards...

Start the REPL on the server, either when the program is launched or in response to a inbound client connection (using e.g. Telnet).

There's a good example here: http://blog.homecloud.ca/2010/03/scripster-interactive-scala-repl-using.html

You could also host an Interpreter instance in your server, then expose a web interface. This is the approach taken by http://www.simplyscala.com/


If you're thinking of debugging, then you'd be better served by this answer: Drop into interpreter during arbitrary scala code location

Community
  • 1
  • 1
Kevin Wright
  • 49,540
  • 9
  • 105
  • 155
  • 1
    Following the answer in the previous similar question http://stackoverflow.com/questions/4131006/attach-a-clojure-repl-to-a-running-jvm it seem it's possible, at least a clojure repl (scala too i suppose) – jneira Nov 09 '10 at 09:23
  • I think this answer is good in showing alternatives and at the time of writing there was no option to do this kind of thing in Scala, but now it seems https://github.com/ngocdaothanh/scalive can offer similar solution. – Gábor Bakos Mar 20 '14 at 08:24
  • I'm starting to think I have a stalker... The downvote on this and a few of my other answers makes no sense whatsoever. – Kevin Wright Jul 12 '14 at 13:38
6

You could use this: https://github.com/wirde/swank-inject

Allows you attach a Clojure repl to a running java process (with remote debugging enabled).

You are also able to specify a number of classes (singletons) for which instances will be found and bound to a symbol available in the repl.

Johan Wirde
  • 61
  • 1
  • 1
1

For Scala REPL connecting to other JVM, take a look at Scalive.

Gábor Bakos
  • 8,982
  • 52
  • 35
  • 52