Hi

On 23 August 2011 12:10, Wanderfels <wanderf...@web.de> wrote:
> Hello,
>
> win XP, clojure 1.2.1 and clojure.contrib-1.2.0.jar here. i want to
> learn clojure (background python and javascript and a bit Haskell) and
> are currently reading the pdf 'Programming Clojure' from 2009.
> In Chapter 1.3: 'Exploring Clojure Libraries' it says:
>
> "
> Clojure code is packaged in libraries. Each Clojure library belongs to
> a namespace, which is analogous to a Java package. You can load a
> Clojure library with require:
>
>  (require quoted-namespace-symbol)
>
> When you require a library named clojure.contrib.str-utils, Clojure
> looks for
> a file named clojure/contrib/str-utils.clj on the CLASSPATH. Try it:
>
>  user=> (require 'clojure.contrib.str-utils)
>  nil
> "
>
> i did. i got:
>
>  user=> (require 'clojure.contrib.str-utils)
>  java.io.FileNotFoundException: Could not locate clojure/contrib/
> str_utils__init.class or clojure/contrib/str_utils.clj on classpath:
> (NO_SOURCE_FILE:0)
>
> i googled a bit. i now know that:
>
> * if you type str-utils it searches for str_utils.clj, not str-
> utils.clj btw.
>  my pdf is wrong (or old) here.
> * setting CLASSPATH doesnt help (JAVA_HOME is set btw).

Depending on how you started the repl this may be ignored.

> * setting classpath directly with ...
>    java -classpath C:\CLOJURE\lib\clojure-contrib-1.2.0.jar -cp
> clojure.jar clojure.main
>  ... doesnt help.

-cp is the short form of -classpath.  If you want more than one thing
on the classpath, you should use:

java -classpath C:\CLOJURE\lib\clojure-contrib-1.2.0.jar;clojure.jar
clojure.main

(assuming you have clojure.jar in the current directory)

or:

java -cp C:\CLOJURE\lib\clojure-contrib-1.2.0.jar;clojure.jar clojure.main

> * doing add-classpath seemed to work for a guy @
> http://stackoverflow.com/questions/1805081/clojure-cant-find-clj-in-local-directory-and-classes-on-classpath
> but a) not for me ...
>
>  user=> (add-classpath "file:///C:/CLOJURE/lib/clojure-
> contrib-1.2.0.jar")
>  WARNING: add-classpath is deprecated
>  nil
>  user=> (println (seq (.getURLs (java.lang.ClassLoader/
> getSystemClassLoader))))
>  (#<URL file:/C:/CLOJURE/bin/clojure.jar>)
>  nil
>
> ... and b) it is depreaced.

It is indeed deprecated and may not work.  Something to do with class
loaders.  Rather just specify the jar in the classpath manually on the
command line, or better, use Leiningen as I'm sure others will tell
you.

> both str_utils__init.class and clojure/contrib/str_utils.clj are
> contained in this contrib jar at the right position. I tried removing
> the numbers from the jar. i tried extracting the contents of the jar.
> i tried moving the contrib folder to C:\CLOJURE\bin\src\clj\clojure.
> li tried moving the contrib jar to C:\CLOJURE\bin.
>
> Now i need a hint. How to import libs in Clojure?
>
> greets, Wanderfels

Basically you were on the right track, but the way you were specifying
the classpath was wrong.

Something like Leiningen or cake can help you with this sort of thing.
 They require you to create a "project", which might seem strange
coming from Python, but since they help with things like the classpath
and downloading dependencies etc. that's generally worth the effort.

e.g.:

lein new myproject
cd myproject
edit project.clj
(add the clojure.contrib.str-utils dependency)
lein deps
lein repl

https://github.com/technomancy/leiningen#readme

-- 
Michael Wood <esiot...@gmail.com>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to