Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add libraries in clojure?

Tags:

clojure

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).

like image 901
datah4ck3r Avatar asked Aug 25 '15 21:08

datah4ck3r


1 Answers

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?

like image 186
ClojureMostly Avatar answered Oct 11 '22 13:10

ClojureMostly