Lee Crabtree
Lee Crabtree

Reputation: 1256

Why can't I require a Java library in my Clojure file?

I've gotten leiningen to find a library I have in a corporate Artifactory repository, and it seems to download it just fine, but when I open try to require it, running the code with lein run comes back with a FileNotFoundException.

My project file looks like this:

(defproject clj-test "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.8.0"]
             [com.ourgroup/library "1.0.0"]]
  :repositories [["releases" {:url "https://url-to-our-repo"
                          :username "username"
                          :password "password"}]]
  :main ^:skip-aot clj-test.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

My single code file looks like this:

(ns clj-test.core
  (:gen-class)
  (:require [library :as lib]))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "And now for something completely different..."))

Upvotes: 2

Views: 503

Answers (1)

Chris Murphy
Chris Murphy

Reputation: 6509

You need to import a class. To get the name of the class take a look inside the jar (or at the Java source code) and find the Java package and class that make up the fully qualified class name that you need to import.

I've edited this. My earlier mistake has been corrected with the comment: "You require namespaces; you import classes. Requiring a class is no good". So for Java interop you need to import classes, the same as you would be doing if you were writing a Java source file.

Upvotes: 2

Related Questions