tags:

views:

390

answers:

2

(I posted this same question on the Clojure list but haven't got an answer yet. Is anyone here ready to help?)

I am going through Programming Clojure and I recently downloaded the code from the books official website. For other utils I can do, for example, (require 'clojure.contrib.str-utils) and it works. But how do I load code from the book? (require 'examples.introduction) throws the following exception:

java.io.FileNotFoundException: Could not locate examples/ introduction__init.class or examples/introduction.clj on classpath: (NO_SOURCE_FILE:0) [Thrown class clojure.lang.Compiler$CompilerException]

Here is the full backtrace:

Backtrace: 0: clojure.lang.Compiler.eval(Compiler.java:4543) 1: clojure.core$eval__3990.invoke(core.clj:1728) 2: swank.commands.basic$eval_region__686.invoke(basic.clj:36) 3: swank.commands.basic$listener_eval__695.invoke(basic.clj:50) 4: clojure.lang.Var.invoke(Var.java:346) 5: user$eval__1200.invoke(NO_SOURCE_FILE) 6: clojure.lang.Compiler.eval(Compiler.java:4532) 7: clojure.core$eval__3990.invoke(core.clj:1728) 8: swank.core$eval_in_emacs_package__307.invoke(core.clj:55) 9: swank.core$eval_for_emacs__384.invoke(core.clj:123) 10: clojure.lang.Var.invoke(Var.java:354) 11: clojure.lang.AFn.applyToHelper(AFn.java:179) 12: clojure.lang.Var.applyTo(Var.java:463) 13: clojure.core$apply__3243.doInvoke(core.clj:390) 14: clojure.lang.RestFn.invoke(RestFn.java:428) 15: swank.core$eval_from_control__310.invoke(core.clj:62) 16: swank.core$eval_loop__313.invoke(core.clj:67) 17: swank.core$spawn_repl_thread__445$fn__476$fn__478.invoke(core.clj: 173) 18: clojure.lang.AFn.applyToHelper(AFn.java:171) 19: clojure.lang.AFn.applyTo(AFn.java:164) 20: clojure.core$apply__3243.doInvoke(core.clj:390) 21: clojure.lang.RestFn.invoke(RestFn.java:428) 22: swank.core$spawn_repl_thread__445$fn__476.doInvoke(core.clj:170) 23: clojure.lang.RestFn.invoke(RestFn.java:402) 24: clojure.lang.AFn.run(AFn.java:37) 25: java.lang.Thread.run(Unknown Source)

I am trying both Clojure Box and Enclojure in NetBeans on Windows XP. Is it a classpath issue? Where should I place the folder that contains code from the book? Please help me out with my variable enviroment settings as well.

+1  A: 

The book suggests that you use the scripts in the bin directory. repl.sh or repl.bat, if you read them, will tell you what you need to put on your classpath for everything to work. If you have trouble setting up the classpath for Clojure or understanding how the path structure corresponds to namespace name structure, there's plenty of questions on SO where this is explained; e.g. see my answer here. (The basics of how to tell java what classpath to use will depend on how you launch it, look it up in the docs for NetBeans if you need to.)

In short, I'd suggest that you take the classpath from repl.sh / repl.bat and use that when launching a REPL through your method of choice. Or just launch a REPL using the appropriate script (that would be the .bat version in your case.)

Finally, it doesn't matter where you put the code as long as you set the classpath accordingly.

Michał Marczyk
A: 

I am going through Programming Clojure using Enclojure on NetBeans. In order to use Enclojure's REPL, I just imported the JAR files in the book's code into my Clojure project. That includes

  1. all the JAR files in the lib/ directory with the exception of jline-0.9.94.jar
  2. a JAR file I created by hand containing the examples/ directory and its contents (PCexamples.jar in the linked image below)

Here is an image of my project's Libraries folder in NetBeans.

mshikaji