6

I have a problem with importing jars in clojure. I used lein to add dependencies. This is code from project.clj

(defproject recommendation "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.5.1"]
                     [org.clojure/java.jdbc "0.0.6"]         ;; jdbc 
                     [mysql/mysql-connector-java "5.1.6"]]
  :aot :all
  :main recommendation.core)

I typed in the command lein deps, and it downloaded 3 jars in lib folder.

This is code from recommendation.core

(ns recommendation.core
(:require [clojure.java.jdbc :as sql]) )

And I get exception:

FileNotFoundException Could not locate clojure/java/jdbc__init.class or clojure/java/jdbc.clj on classpath:   clojure.lang.RT.load (RT.java:443)

Can anybody tell me where i am wrong and what to do?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
user3549602
  • 69
  • 1
  • 8

2 Answers2

4

here's my dependency line:

[org.clojure/java.jdbc "0.2.3"]

Heres the require line from one of my projects that use jdbc

(:require [clojure.java [jdbc :as sql]])

If none of this helps here are my standard leiningen fixing steps:

  1. lein deps and look for errors
  2. lein clean
  3. lein upgrade
  4. lein deps :tree and look for strangeness
  5. rm -rf target/ # this one has only helped me with messed up native deps.
  6. rm ~/.m2/repository -rf # this is the last resort, it's lots of downloading.
  7. join #leiningen on irc.freenode.net and ask for help

PS: I found this video helpful in getting a handle on namespaces.

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
  • Just `(:require [clojure.java.jdbc :as sql])` also works. You rarely want to do the nested vector syntax. It tends to make things difficult to read. – Rayne Apr 18 '14 at 18:24
  • i am getting the same error. I dont know what is wrong, is it version of jar, or i missed some step to include that jar in project. When i type lein classpath, i see that jar in lib folder.. – user3549602 Apr 18 '14 at 19:09
0

update the dependencies line to the latest jdbc.java version: https://github.com/clojure/java.jdbc

at the time of writing it is version 0.7.3:

:dependencies [[org.clojure/clojure "1.8.0"]  [org.clojure/java.jdbc "0.7.3"]]
Damien Mattei
  • 358
  • 4
  • 9