About paths

0 views
Skip to first unread message

Paulo Candido

unread,
May 3, 2010, 4:44:57 PM5/3/10
to clo...@googlegroups.com
I have a very basic doubt:

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?

regards

Paulo

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Alex Osborne

unread,
May 3, 2010, 5:48:09 PM5/3/10
to clo...@googlegroups.com
Paulo Candido <paulo....@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.
Reply all
Reply to author
Forward
0 new messages