Paulo Candido <paulo.cand...@gmail.com> writes:

> I have a script, say "foo.clj" in a namespace "com.company.ns".
> "foo.clj" uses functions from another script, "bar.clj" in the same
> namespace. "foo"'s namespace has the line "(:use com.company.ns.bar)".
> It works in the REPL, it works inside Netbeans with Enclojure.
>
> Now I'm stuck trying to make "foo.clj" run as a standalone script. I
> tried including the path to "bar" in the classpath (-cp) but it does
> not work (at least not in the many ways I tried). Do I have to put all
> scripts in a jar or is there a way to inform clojure.main about the
> location of used/required scripts?

Clojure will search for files relative to the Java classpath.  So it
will search for com.company.ns.foo in
$CLASSPATH/com/company/ns/foo.clj.

You can set the classpath either by setting the CLASSPATH environment
variable or by passing the -cp option to java.  So for example if you
have the following project layout and Java 6:

myproject/
  lib/
    clojure.jar
    clojure-contrib.jar
  src/com/company/ns
    foo.clj
    bar.clj

Then from inside the myproject directory, I'd start a main function in
the foo.clj script with:

java -cp 'src:lib/*' clojure.main -e "(use 'com.company.ns.foo) (main)"

If you're on Windows you may need to use semicolons instead of colons to
separate classpath entries.

-- 
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
  • About paths Paulo Candido
    • Re: About paths Alex Osborne

Reply via email to