Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch a clojure repl with access to a jar

I'm new to clojure. I have a jar file I want to play with in a clojure repl, but I've failed to do so with leiningen 2.

I have tried placing the jar file in src/myjar.jar and also in src/org/mydomain/myjar.jar

When I run lein repl I get errors stating that leiningen can not find my artifact, and a reference to a page about repeatability which I do not understand.

Here is my project.clj (with the real name of myjar)

(defproject cljliveordead "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [org.allen.temporalintervalrelationships/time "0.2" :extension "jar"]])
like image 834
Lyn Headley Avatar asked Jun 25 '12 23:06

Lyn Headley


People also ask

How do I launch REPL in Clojure?

To start a REPL session in Eclipse, click the Menu option, go to Run As → Clojure Application. This will start a new REPL session in a separate window along with the console output.

What is Clojure REPL?

A Clojure REPL (standing for Read-Eval-Print Loop) is a programming environment which enables the programmer to interact with a running Clojure program and modify it, by evaluating one code expression at a time.

How do you abruptly stop execution in the REPL?

You can just press ctrl-d (*nix) or ctrl-z (Windows) to exit the REPL.


2 Answers

You can use local jars using the lein-localrepo plugin. Add this line to your project.clj

:plugins [[lein-localrepo "0.4.0"]]

Then install the jar to the local repository using

lein localrepo install <path-to-jar> org.allen.temporalintervalrelationships/time 0.2

You can check that the file is installed by running lein localrepo list and check that lein can resolve the project dependencies using lein deps. If all is well then you can start playing with the jar using lein repl.

Leiningen doesn't like local jars due to its goal of repeatable builds. If this was a real project using a third party closed source jar then the best thing to do is install it in a local Nexus repository and add a reference to that repository to your project.

However, this all seems a bit heavyweight for what you are trying to achieve. If all you want to do is play with the jar in the REPL then create a simple project like this

(defproject clojure-time "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [com.cemerick/pomegranate "0.0.13"]])

and use the pomegranate library to add the jar to your classpath manually

(require '[cemerick.pomegranate :as p])
(p/add-classpath "jsr-310-ri-0.6.3.jar")
(javax.time.Instant/now)

and play away.

like image 180
Jeff Johnston Avatar answered Sep 29 '22 12:09

Jeff Johnston


the hackish way is to just put it into /proiject/path/lib/ and the 'proper' way is to:

  • add a dependency for it to your project
  • run lein deps which will print the command for installing the jar to your local maven repo
  • run the command leiningen gives you with the path to your jar
  • run lein deps again
like image 42
Arthur Ulfeldt Avatar answered Sep 29 '22 11:09

Arthur Ulfeldt