Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import a local java library in clojure? (lein)

I'm trying to use a java library (jar file) called DragonConsole that is not on maven central or clojars.

I want to import this library in my clojure application, but so far I can't figure out how to do so.

I tried setting up a local maven repo, but I don't think I did it right.

lein deps gives me this error:

(Retrieving dragonconsole/dragonconsole/3.0.0/dragonconsole-3.0.0.pom from local)
(Could not transfer artifact dragonconsole:dragonconsole:pom:3.0.0 from/to local)
(file:/home/michael/clj/enclojed/maven_repository/): no supported algorithms found)

project.clj:

:dependencies [[org.clojure/clojure "1.6.0"]
               [clojure-lanterna "0.9.4"]
               [dragonconsole "3.0.0"]]
:repositories [["local" {:url ~(str (.toURI (java.io.File. "maven_repository")))}]]

project folder:

maven_repository/DragonConsolev3.jar
maven_repository/dragonconsole/dragonconsole/maven-metadata-local.xml
maven_repository/dragonconsole/dragonconsole/3.0.0/dragonconsole-3.0.0.pom
doc/...
src/...
test/...
resources/...
project.clj

If there's any other files you need to see, check the git page.

like image 547
Michael Auderer Avatar asked Jul 25 '14 20:07

Michael Auderer


People also ask

What is Lein in Clojure?

Leiningen is a modern build system for our Clojure projects. It's also written and configured entirely in Clojure. It works similarly to Maven, giving us a declarative configuration that describes our project, without needing to configure exact steps to be executed.


1 Answers

This is probably the easiest way. Do you have a ~/.m2 directory?

1) Add your dependency in project.clj e.g. :dependencies [[dragonconsole "3.0.0"]]

When you run lein run/test/etc it will attempt to pull the library from maven central and clojars, and it will create a path for you under ~/.m2, such as ~/.m2/repository/dragonconsole/dragonconsole/3.0.0/

Note: if a library with the same name and version exists, simply delete the contents downloaded (a jar, pom, etc...)

2) Create a symbolic link to your jar under the dragonconsole directory in ~/.m2, e.g. ln -s /path/to/project/dragonconsole-3.0.0.jar ~/.m2/repository/dragonconsole/...

This time when you run lein run/test/etc it will work. This is the easiest and cleanest approach I've found although I haven't had much time to poke around. I like it because your code and build process doesn't change any more than it needs to (just a single line to add the dependency).

For production I'd look for a way to add a lein repository "source", so it looks in my custom repo, then maven central, then clojars.

like image 156
jassa Avatar answered Nov 14 '22 23:11

jassa