Remote debugging Clojure and Leiningen

March 12, 2010

Debuggers like JSwat and Eclipse can be remotely attached to live Clojure processes via TCP, but you have to tell the JVM to enable remote debugging when you start it. Leiningen does not presently have an (obvious) way to set java command line flags in project.clj, but it does pass the JAVA_OPTS environment variable to the JVM, so you can do:

JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n" lein swank
# or "lein repl", etc.

to enable remote debugging. Watch the output for the port it allocates, and put that into JSwat/Eclipse/etc.

Leiningen seems to create more than one JVM when it starts up (one for Leiningen itself and one for the application?), so you can’t specify a particular port to use in JAVA_OPTS (which you could normally do with the “address=9876” option.) If you do, both JVMs will try to use the same TCP port and your program will crash at startup.

Popularity: 8% [?]

tags: ,
posted in Tech by Paul Legato

Follow comments via the RSS Feed | Leave a comment | Trackback URL

Leave Your Comment

 
Copyright © 2009 Paul Legato. All rights reserved. Theme based on Shlomi Noach, openark.org