I'm trying to add paths to my classpath in the Clojure REPL that I've set up in Emacs using ELPA. Apparently, this isn't the $CLASSPATH environment variable, but rather the swank-clojure-classpath variable that Swank sets up. Because I used ELPA to install Swank, Clojure, etc., there are a ton of .el files that take care of everything instead of my .emacs file. Unfortunately, I can't figure out how to change the classpath now.
I've tried using (setq 'swank-clojure-extra-classpaths (list ...)) both before and after the ELPA stuff in my .emacs, and I've tried adding paths directly to swank-clojure-classpath in .emacs, .emacs.d/init.el, and .emacs.d/user/user.el, but nothing works.
What I'm ultimately trying to do is to add both the current directory "." and the directory in which I keep my Clojure programs. I'm assuming swank-clojure-classpath is the thing I need to set here. Thanks for your help.
As mac says, you can use
M-x swank-clojure-project
to establish a slime REPL to a clojure project; the command will ask you for your projects root directory, and will establish a classpath that includes a variety of directories including src/ lib/ and resources/ if they are present.
Alternatively, if you are using leiningen, you can start that in a terminal with the command
$ lein swank
from inside your project root directory. This will establish a standard project classpath (as above). From here you can connect to this running process via Emacs with the command
M-x slime-connect
Finally a third option which I'd recommend is to connect via Emacs/slime (with M-x slime-connect
) to a process started by your own shell script which specifies a custom set of JVM command line arguments e.g.
#!/bin/bash
java -server -cp "./lib/*":./src clojure.main -e "(do (require 'swank.swank) (swank.swank/start-repl))"
This allows you explicit control over how the VM is started, and is likely similar to what you will likely have to do in production anyway.
You want:
M-x swank-clojure-project
This adds all jars in your /lib dir.
If you want to :use a clojure file (bar.clj), in for instance /foo you would do:
(ns foo
(:use foo.bar))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With