Adding directory to classpath in leiningen

1,075 views
Skip to first unread message

Cecil Westerhof

unread,
Mar 12, 2015, 4:10:27 AM3/12/15
to clo...@googlegroups.com
I have some files in:
    ~/Clojure
that I want to use in a project I start with:
    lein repl

But I do not see how to do this. How can I acomplish this?

--
Cecil Westerhof

Hildeberto Mendonça

unread,
Mar 12, 2015, 7:00:23 AM3/12/15
to clo...@googlegroups.com
$ cd ~/Clojure
$ lein repl

Your code in the repl will see the path ~/Clojure as working directory, so any file there will be accessible to your code by simply using the name of the file. If you have sub-directories then add the relative path: "path/to/the/file/the-file.txt"

--
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
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Hildeberto Mendonça, Ph.D
Blog: http://www.hildeberto.com
Community: http://www.cejug.net
Twitter: https://twitter.com/htmfilho

Cecil Westerhof

unread,
Mar 12, 2015, 7:23:49 AM3/12/15
to clo...@googlegroups.com
2015-03-12 12:00 GMT+01:00 Hildeberto Mendonça <m...@hildeberto.com>:
$ cd ~/Clojure
$ lein repl

Your code in the repl will see the path ~/Clojure as working directory, so any file there will be accessible to your code by simply using the name of the file. If you have sub-directories then add the relative path: "path/to/the/file/the-file.txt"

​That is not going to work, because I want to use the files in the project that resides in:
    ~/Clojure/quotes

I could move the files to there, but there is a big change that I want to use them in other projects also.
I could use (soft) links, but I was just wondering if it would be possible to extend the classpath.

By the way: I moved them to:
    ~/Clojure/repl
that is a better place I think.

 
On Thu, Mar 12, 2015 at 9:10 AM, Cecil Westerhof <cldwes...@gmail.com> wrote:
I have some files in:
    ~/Clojure
that I want to use in a project I start with:
    lein repl

But I do not see how to do this. How can I acomplish this?

--
Cecil Westerhof

Jony Hudson

unread,
Mar 12, 2015, 10:44:14 AM3/12/15
to clo...@googlegroups.com
Putting them in the working directory does not add them to the classpath. Leiningen used to have an 'escape hatch' to allow local libraries to be added to the classpath, but that was removed. The right way to do it now is to make the artefacts you want on the classpath available to Maven. The easiest way to do this is to install them into your local repo. I've found


is really very helpful for adding arbitrary jars to my local repo in the past.


Jony

John Gabriele

unread,
Mar 12, 2015, 11:58:53 AM3/12/15
to clo...@googlegroups.com
Hi Cecil,

I think what you want to do is create a library project to house your common code, install the library to your local repository, then use it from your project:

~~~
cd ~/dev
lein new my-stuff/my-lib
cd my-lib
# edit src/my_stuff/my_lib.clj , adding your common code here
lein install

# Ok, that library is now ready to use from your project.
cd ~/dev
lein new app my-proj
cd my-proj
# edit project.clj to have `[my-stuff/my-lib "0.1.0-SNAPSHOT"]` in :dependencies
# edit src/my_proj/core.clj to have `(:require [my-stuff.my-lib :as my)` in
#   the ns macro at the top
# do something like `(my/foo 3)` from inside `-main`.
lein run
~~~

-- John

John Gabriele

unread,
Mar 12, 2015, 12:05:04 PM3/12/15
to clo...@googlegroups.com
Forgot to add, you can then run `lein repl` from my-proj as usual, and have easy access to your library code:

~~~
$ cd ~/dev/my-proj
$ lein repl
> my-proj.core=> (my/foo 4)
4 Hello, World!
nil
~~~
Reply all
Reply to author
Forward
0 new messages