5

Everywhere I see, it is suggested that I add :dependencies in project.clj and run lein deps. Where are these downloaded? What is my CLASSPATH and how can I add my own JARs to my clojure project?

While the answer for

Dependencies in maven local repositories with leiningen

kind of solves my need, I am not marking it duplicate as what I am asking is much simpler (being a beginner, who does not have much experience with Java to know about Maven). I am still finding it hard to understand where clojure ends and leiningen begins.

The thing I was looking for is a way to add library like we do in most other languages (e.g. copy JAR to project directory and import in code).

datah4ck3r
  • 1,174
  • 1
  • 8
  • 19
  • Your classpath is dynamically set by Leiningen. If you're trying to set it by hand, you're Doing It Wrong. – Charles Duffy Aug 25 '15 at 21:39
  • 1
    (And where the files go depends on your Maven configuration, but by default they'll be under `~/.m2/repo`). – Charles Duffy Aug 25 '15 at 21:40
  • ...you shouldn't be needing to bother with `lein deps` either. Whenever you run any `lein compile`, or `lein repl`, or `lein uberjar`, or other target, everything appropriate and necessary will be pulled in for you. – Charles Duffy Aug 25 '15 at 21:40
  • ...as for how to add *your own* jars, the commonly accepted approach is to create your own Maven repository. This is well-documented elsewhere, including in prior Q&A here. – Charles Duffy Aug 25 '15 at 21:41
  • 1
    Perhaps this is duplicate of http://stackoverflow.com/questions/8738664/dependencies-in-maven-local-repositories-with-leiningen ? – Charles Duffy Aug 25 '15 at 21:42
  • I don't think so, Charles. This seems like a general "what the heck are dependencies" question, where the linked one is about including a foreign library. – amalloy Aug 25 '15 at 22:33

2 Answers2

5

This is great question since it's not clear at all. Leiningen is often a black hole and if something isn't working it's often hard to debug.

I just recently had to do some manual scripting and leiningen does help you with finding out these things.

Where are these downloaded?

The directory is in $HOME/.m2. This is Maven's: http://maven.apache.org/settings.html

What is my classpath?

The classpath is set depending on your :dependencies as well as your :source-paths and :resource-paths vectors.

You can find out your classpath like this:

lein classpath

This will print a huge list depending on your configuration.

You could --for instance-- then run a script:

    java -cp cljs-1.7.xx.jar:scripts:$(lein with-profile +dev-cljs classpath) clojure.main scripts/cljs-build.clj dev

That has access to all your projects dependencies and loads them properly.

Although you could use lein run to achieve something similar:

lein with-profile +dev-cljs run -m clojure.main scripts/cljs-build.clj dev

How do I add my own JARs?

See: leiningen - how to add dependencies for local jars?

Community
  • 1
  • 1
ClojureMostly
  • 4,652
  • 2
  • 22
  • 24
0

Run lein install from your library's project dir. Add an entry to :dependencies in client's project.clj. Make sure the lib name/version and its reference match (eg. [mylib "0.0.1-SNAPSHOT"]). Hope this helps, forget about jar loc and cp for now.