Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to require a jar file in Clojure REPL?

Tags:

java

clojure

It's easy to require a package from clojure:

user=> (require 'clojure.core)
nil

But how can I require a .jar file inside Clojure?

(I'm trying to learn lein. Leiningen is useful to big projects rather than small scripts. So I want to figure out that what's the best method to use a jar package in my Clojure scripts and in REPL.)

like image 861
jiyinyiyong Avatar asked Nov 05 '12 05:11

jiyinyiyong


3 Answers

Although it's possible to add a jar to an application at runtime with the help of the Pomegranate library, it's highly discouraged as:

  1. It hides the dependency from the outside, and end users won't know they need it to run the code.
  2. The jar itself can depend on other jar files (and hence put strain on end users to figure it out)

I think I'm repeating the other respondents, but thought I'd add the points to validate their advices.

As a matter of fact, lein2 uses pomegranate under the covers, just for the purpose of not having to restart REPL after a dependency is needed. It's only for development purposes.

like image 72
Jacek Laskowski Avatar answered Oct 17 '22 07:10

Jacek Laskowski


I don't think you can. The REPL has to be started with the JAR on the classpath.

like image 34
Alex Baranosky Avatar answered Oct 17 '22 09:10

Alex Baranosky


Have a look at the Pomegranate library.

like image 1
Maurits Rijk Avatar answered Oct 17 '22 09:10

Maurits Rijk