My biggest frustration is gettting the classpath & current directory
set up correctly.
I have main my code in package folders under src/main/clojure, and my
tests under src/test/clojure ... and I need src/main/resources and
src/test/resources on the classpath as well.
I'm wondering what other people do to manage these issues. Currently,
I'm using Ant to run my tests, but doing anything in the REPL is hard,
as I have to carefully load my namespaces in the right order, as they
can't be resolved automatically (as that is dependent on having the
classpath set up correctly).
--
Howard M. Lewis Ship
Creator of Apache Tapestry
Director of Open Source Technology at Formos
What I do is run clojure under slime and have an external script that
creates the correct classspath and then launches clojure. The script
(called clojure) is hooked into slime using something like:
(setq slime-lisp-implementations
`((k-clj ("clojure" "--project" ,(expand-file-name "~/work/kineto")
"--no-rlwrap")
:init swank-clojure-init)
;; ...
(ccl ("/usr/local/bin/ccl"))))
The script makes many assumptions about what needs to be in the
classpath, but it works well for me. I don't expect the script to be
useful to anyone else, but you can look at it in
http://github.com/ctdean/clojure-launch/tree/master
It's written in Ruby and is Unix-centric.
Cheers,
Chris Dean
> I have main my code in package folders under src/main/clojure, and my
> tests under src/test/clojure ... and I need src/main/resources and
> src/test/resources on the classpath as well.
>
> I'm wondering what other people do to manage these issues. Currently,
> I'm using Ant to run my tests, but doing anything in the REPL is hard,
> as I have to carefully load my namespaces in the right order, as they
> can't be resolved automatically (as that is dependent on having the
> classpath set up correctly).
I use the clojure-project function to launch slime; it sets up the
classpath according to my project conventions:
As long as you unpack your deps all in one place and stick to the same
classpath conventions, the fact that you can't change the classpath at
runtime is not a significant problem.
For running tests, I wrote clojure-test-mode:
(This hasn't been updated to reflect the move of test-is -> clojure.test
yet; patches welcome.)
It will run tests in-process via SLIME. Of course, you can't rely on
this solely because your results can be affected by a "dirty JVM", so
it's important to do a sanity-check with a fresh instance before each
check-in. But running in SLIME speeds up the test-implement-refactor
rhythm pretty significantly for me at least.
-Phil
> As long as you unpack your deps all in one place and stick to the same
> classpath conventions, the fact that you can't change the classpath at
> runtime is not a significant problem.
Can you kindly explain exactly what kind of conventions you follow as
far as laying out the code, dependencies are concerned?
A sample directory structure would help.
Regards,
BG
--
Baishampayan Ghose <b.g...@ocricket.com>
oCricket.com
> Phil,
>
>> As long as you unpack your deps all in one place and stick to the same
>> classpath conventions, the fact that you can't change the classpath at
>> runtime is not a significant problem.
>
> Can you kindly explain exactly what kind of conventions you follow as
> far as laying out the code, dependencies are concerned?
Sure. It's explained in this post.
http://technomancy.us/126#projects
Basically:
* Source under src/
* Tests under test/
* AOT bytecode under target/classes/
* Dependencies all unpacked together under target/dependency/
Since I use the same conventions for every single project, I never have
to change my classpath.
-Phil
> How well does the Emacs Starter Kit work in AquaEmacs?
Unfortunately I can't test it with Aquamacs myself since it's not
portable, but I've heard reports of it working well. Aquamacs is
incompatible with GNU Emacs in a number of undocumented edge-cases, but
the Starter Kit is pretty simple.
You'll definitely have fewer compatibility issues in the long run with
GNU Emacs though, especially now that the 23 release (scheduled for
release this Wednesday) includes a Cocoa port.
-Phil
> What version of emacs should I be using? Currently I'm using Emacs
> 22.1.1, which I believe is the built-in version for mac.
That should do the trick; you might as well wait for the release if you
want to get version 23 since it's so soon. The package manager situation
on the Mac leaves much to be desired.
> Marking those packages, then 'x' to execute, generates a number of errors:
Those are mostly just warnings; the only error (for clojure-test) is the
fact that slime hasn't been installed. Once you've got clojure-mode
installed and run M-x clojure-install, the slime dependency will be
satisfied. So that shouldn't be a problem; just go ahead.
-Phil
Many thanks.
I tried using your clojure-project script, I am facing two problems:
1. When I try running the function on a fresh Emacs, it bails out
because swank-clojure-extra-vm-args is not defined at that stage. I
fixed that by running the SLIME repl once before running the
clojure-project function.
2. After that, it still fails to work as it remains stuck at the
"Polling /tmp/slime.634..." stage.
Any pointers?
IntelliJ has many strengths, but a simple, transparent mechanism to add an arbitrary directory or jar to the classpath isn't among them.
> Another question. Where do I put the clojure & clojure-contrib JAR files?
If you use the M-x clojure-install command, this should get all the dependencies.
If you're getting stuck at the "Polling" stage, it's probably because
you didn't do M-x clojure-install. If you do that and you still see the
error, then paste the contents of your *inferior-lisp* buffer for
debugging.
-Phil
While we're on this subject, anybody know the same information for La Clojure? That is, how to set up the current directory and classpath so one can compile java classes from Clojure?
IntelliJ has many strengths, but a simple, transparent mechanism to add an arbitrary directory or jar to the classpath isn't among them.
>> Another question. Where do I put the clojure & clojure-contrib JAR files?
>
> If you use the M-x clojure-install command, this should get all the dependencies.
>
> If you're getting stuck at the "Polling" stage, it's probably because
> you didn't do M-x clojure-install. If you do that and you still see the
> error, then paste the contents of your *inferior-lisp* buffer for
> debugging.
OK. I found the problem. I didn't unzip clojure.jar inside
target/dependency. Now it works fine, which brings me to another issue.
Do I have to unzip all dependencies into target/dependency? Can't I work
with just JAR files? For example, I really wanted to put the
clojure-contrib.jar in the folder, but it didn't work. I had to unzip it
and then it worked. Same with some other external deps.
Is there any way for me to just put the JAR files somewhere and get them
added to the classpath?
Thanks in advance.
Thanks in advance.
Regards,
BG
--
Baishampayan Ghose <b.g...@ocricket.com>
oCricket.com
> For me it works like this
> .bashrc
> export CLASSPATH=.:/usr/local/clojure/clojure-1.0.0.jar
>
> .emacs
> (setq inferior-lisp-program "java -server clojure.lang.Repl")
> (setq load-path (cons "/usr/local/clojure/clojure-mode" load-path))
> (require 'clojure-mode)
I was not talking about the Clojure JAR. I wanted a nice way to use
external library JARs along with the clojure-project function which Phil
has written.
>> Is there any way for me to just put the JAR files somewhere and get them
>> added to the classpath?
>
> Put them in a lib/ folder at your project root.
Many thanks Luke. That worked. I should have looked at the source of
clojure-project before.
Thanks again.