Korma not loading JDBC correctly - clojure

I would really like to use Korma for my project, but every time I try to test it in my REPL, it throws the following error:
core=> (require 'korma.db)
FileNotFoundException Could not locate clojure/java/jdbc/internal__init.class or clojure/java/jdbc/internal.clj on classpath: clojure.lang.RT.load (RT.java:432)
I have the following in my 'core' namespace:
(ns core
(:require [clojure.java.jdbc :as sql]))
and the following in my project.clj:
(defproject wknd "1.0.0-SNAPSHOT"
:description "weekend side project"
:dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/clojure-contrib "1.2.0"]
[org.xerial/sqlite-jdbc "3.7.2"]
[org.clojure/java.jdbc "0.2.2"]
[korma "0.3.0-beta9"]]
:dev-dependencies [[org.clojars.scott/lein-nailgun "1.1.0"]])
I am just starting out on clojure and have no idea why I'm getting this error. I've searched around and couldn't find similar issues elsewhere.

From the author:
Korma hadn't been upgraded to the latest JDBC since the reorganization
of it. Try beta11, should be fixed.
Cheers, Chris.
and this error disappeared for me.

Related

Getting started with datomic and clojure - Could not locate datomic/api__init.class on classpath

I am trying to run datomic's in-memory database with this tutorial https://clojureverse.org/t/a-quick-way-to-start-experimenting-with-datomic/5004 with the free version. I downloaded the .zip file and put it in program files. Then I created a project with leiningen and I did the other steps indicated in the tutorial, but when I want to evaluate the lines with the repl for creating the database and connection it throws:
"Error:
Syntax error compiling at (c:\Users\usuario\Desktop\clojure\datomic-shortcut\src\datomic_shortcut\core.clj:7:3).
No such namespace: d"
... and when I evaluate the entire file, the following:
Evaluating file: core.clj
Syntax error (FileNotFoundException) compiling at (c:\Users\usuario\Desktop\clojure\datomic-shortcut\src\datomic_shortcut\core.clj:1:1).
Could not locate datomic/api__init.class, datomic/api.clj or datomic/api.cljc on classpath.
Evaluation of file core.clj failed: class clojure.lang.Compiler$CompilerException
When checking the .m2 folder there is no datomic's dependency, even after trying 'lein deps'
I think it can be solved with lein pom/jar/install sequence but I dont find where or I dont know how to download the .jar file.
Any help or information is welcome.. thanks!
-------------EDIT--------------------
Im sorry, the .m2 folder contains the ...m2\repository\com\datomic\datomic-free\0.9.5697\datomic-free-0.9.5697.jar file indeed.
No errors with 'lein deps'
My project.clj:
(defproject datomic-shortcut "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.10.1"]
[com.datomic/datomic-free "0.9.5697"]]
:source-paths ["src"]
:repl-options {:init-ns datomic-shortcut.core})
My core.clj:
(ns datomic-shortcut.core
(:require [datomic.api :as d]))
(def db-uri "datomic:mem://foo")
(comment
(d/create-database db-uri)
(def conn (d/connect db-uri)))
I realized the classpath hasn't the .jar file in it.
C:\Users\usuario\Desktop\clojure\datomic-shortcut>lein classpath
=>
C:\Users\usuario\Desktop\clojure\datomic-shortcut\test;
C:\Users\usuario\Desktop\clojure\datomic-shortcut\src;
C:\Users\usuario\Desktop\clojure\datomic-shortcut\dev-resources;
C:\Users\usuario\Desktop\clojure\datomic-shortcut\resources;
C:\Users\usuario\Desktop\clojure\datomic-shortcut\target\classes;
C:\Users\usuario\.m2\repository\com\datomic\datomic-lucene-core\3.3.0\datomic-lucene-core-3.3.0.jar;
C:\Users\usuario\.m2\repository\com\google\guava\guava\18.0\guava-18.0.jar;
C:\Users\usuario\.m2\repository\com\h2database\h2\1.3.171\h2-1.3.171.jar;
C:\Users\usuario\.m2\repository\org\apache\activemq\artemis-commons\1.4.0\artemis-commons-1.4.0.jar;
C:\Users\usuario\.m2\repository\nrepl\nrepl\0.6.0\nrepl-0.6.0.jar;
C:\Users\usuario\.m2\repository\org\apache\tomcat\tomcat-juli\7.0.27\tomcat-juli-7.0.27.jar;
C:\Users\usuario\.m2\repository\clojure-complete\clojure-complete\0.2.5\clojure-complete-0.2.5.jar;
C:\Users\usuario\.m2\repository\org\slf4j\jul-to-slf4j\1.7.7\jul-to-slf4j-1.7.7.jar;
C:\Users\usuario\.m2\repository\leinjacker\leinjacker\0.4.1\leinjacker-0.4.1.jar;
C:\Users\usuario\.m2\repository\org\jboss\logging\jboss-logging\3.3.0.Final\jboss-logging-3.3.0.Final.jar;
C:\Users\usuario\.m2\repository\org\slf4j\jcl-over-slf4j\1.7.7\jcl-over-slf4j-1.7.7.jar;
C:\Users\usuario\.m2\repository\org\clojure\core.contracts\0.0.1\core.contracts-0.0.1.jar;
C:\Users\usuario\.m2\repository\org\codehaus\janino\commons-compiler\2.6.1\commons-compiler-2.6.1.jar;
C:\Users\usuario\.m2\repository\com\datomic\datomic-free\0.9.5697\datomic-free-0.9.5697.jar;
C:\Users\usuario\.m2\repository\org\clojure\core.unify\0.5.3\core.unify-0.5.3.jar;
C:\Users\usuario\.m2\repository\org\apache\johnzon\johnzon-core\0.9.4\johnzon-core-0.9.4.jar;
C:\Users\usuario\.m2\repository\commons-beanutils\commons-beanutils\1.9.2\commons-beanutils-1.9.2.jar;
C:\Users\usuario\.m2\repository\org\slf4j\log4j-over-slf4j\1.7.7\log4j-over-slf4j-1.7.7.jar;
C:\Users\usuario\.m2\repository\useful\useful\0.8.5-alpha2\useful-0.8.5-alpha2.jar;
C:\Users\usuario\.m2\repository\org\slf4j\slf4j-nop\1.7.7\slf4j-nop-1.7.7.jar;
C:\Users\usuario\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;
C:\Users\usuario\.m2\repository\org\clojure\tools.cli\0.3.5\tools.cli-0.3.5.jar;
C:\Users\usuario\.m2\repository\lein-datomic\lein-datomic\0.2.0\lein-datomic-0.2.0.jar;
C:\Users\usuario\.m2\repository\org\fressian\fressian\0.6.5\fressian-0.6.5.jar;
C:\Users\usuario\.m2\repository\org\apache\geronimo\specs\geronimo-json_1.0_spec\1.0-alpha-1\geronimo-json_1.0_spec-1.0-alpha-1.jar;
C:\Users\usuario\.m2\repository\me\raynes\conch\0.4.0\conch-0.4.0.jar;
C:\Users\usuario\.m2\repository\org\apache\activemq\artemis-core-client\1.4.0\artemis-core-client-1.4.0.jar;
C:\Users\usuario\.m2\repository\org\slf4j\slf4j-api\1.7.7\slf4j-api-1.7.7.jar;
C:\Users\usuario\.m2\repository\org\clojure\clojure\1.10.1\clojure-1.10.1.jar;
C:\Users\usuario\.m2\repository\io\netty\netty-all\4.0.39.Final\netty-all-4.0.39.Final.jar;
C:\Users\usuario\.m2\repository\org\clojure\core.specs.alpha\0.2.44\core.specs.alpha-0.2.44.jar;
C:\Users\usuario\.m2\repository\org\codehaus\janino\commons-compiler-jdk\2.6.1\commons-compiler-jdk-2.6.1.jar;
C:\Users\usuario\.m2\repository\org\clojure\tools.macro\0.1.1\tools.macro-0.1.1.jar;
C:\Users\usuario\.m2\repository\org\apache\tomcat\tomcat-jdbc\7.0.27\tomcat-jdbc-7.0.27.jar;
C:\Users\usuario\.m2\repository\commons-codec\commons-codec\1.10\commons-codec-1.10.jar;
C:\Users\usuario\.m2\repository\org\clojure\spec.alpha\0.2.176\spec.alpha-0.2.176.jar
So then I tried:
C:\Users\usuario\Desktop\clojure\datomic-shortcut>java -cp C:/Users/usuario/.m2/repository/com/datomic/datomic-free/0.9.5697/datomic-free-0.9.5697.jar clojure.main
Error: no se ha encontrado o cargado la clase principal clojure.main

java.io.FileNotFoundException: Could not locate clojure/spec/alpha__init.class or clojure/spec/alpha.clj on classpath

I was trying to understand Clojure spec. While setting up a clojure project I am getting following error while requiring the clojure.spec.alpha:
Exception in thread "main" java.io.FileNotFoundException: Could not locate clojure/spec/alpha__init.class or clojure/spec/alpha.clj on classpath., compiling:
at clojure.lang.Compiler.load(Compiler.java:7391)
at clojure.lang.Compiler.loadFile(Compiler.java:7317)
at clojure.main$load_script.invokeStatic(main.clj:275)
at clojure.main$script_opt.invokeStatic(main.clj:335)
at clojure.main$script_opt.invoke(main.clj:330)
at clojure.main$main.invokeStatic(main.clj:421)
at clojure.main$main.doInvoke(main.clj:384)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.lang.Var.invoke(Var.java:379)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
My project.clj:
(defproject testing "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.9.0"]
[org.clojure/spec.alpha "0.1.143"]
[org.clojure/core.specs.alpha "0.1.10"]])
and core.clj:
(ns testing.core
(:require [clojure.spec.alpha :as s]))
(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
I will be thankful, if someone can help me out.
I did a lein clean and it started working
For those who experience this problem on 1.9, see https://groups.google.com/forum/#!msg/clojure/-ovhQXtzhgw/XBm_rfcICgAJ
With 1.8, you can just run java -jar clojure-1.8.0.jar that you have in your .m2 and RELP will start instantaneously. With 1.9, it's no longer the case. You need additional libraries that you might not have in your .m2 by default.
You will have them though if you install you Clojure based on official guide.
I had the same error, I don't know clojure but had to fix some NoClassDefFoundError exceptions testing Kafka Storm using org.apache.storm.kafka.KafkaSpout.
First exception was: NoClassDefFoundError: clojure/lang/IFn
This I fixed by including clojure-1.9.0.jar in the classpath.
Next, this exception:
FileNotFoundException: Could not locate clojure/spec/alpha__init.class or clojure/spec/alpha.clj on classpath
later realized they have another jar spec.alpha-0.1.143.jar for this.
Hope this helps someone else!
What worked for me was adding test.check library as a dependency to my classpath

lein ring server-headless fails when including datomic dependency

My goal is to create a web application using compojure and attach datomic as database. Individually, these two components work fine. However, when I try to start the server with
lein ring server-headless (including datomic as a dependency) with an enourmous error. The head of the error output:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/util/component/AggregateLifeCycle, compiling:(ring/adapter/jetty.clj:1:1)
at clojure.lang.Compiler.load(Compiler.java:7391)
at clojure.lang.RT.loadResourceScript(RT.java:372)
at clojure.lang.RT.loadResourceScript(RT.java:363)
at clojure.lang.RT.load(RT.java:453)
at clojure.lang.RT.load(RT.java:419)
at clojure.core$load$fn__5677.invoke(core.clj:5893)
using the project.clj
(defproject pinvest "0.1.0-SNAPSHOT"
:description "foobar"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/core.async "0.3.442"]
[org.clojure/tools.namespace "0.2.11"]
[compojure "1.5.1"]
[ring/ring-defaults "0.2.1"]
[com.datomic/clj-client "0.8.606"]]
:plugins [[lein-ring "0.9.7"]]
:ring {:handler pinvest.handler/app}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.0"]]}})
Initially generated with lein new compojure foo. The dependency com.datomic/clj-client is causing the problem in starting the server.
I tried excluding some dependencies, by making my project.clj with
[com.datomic/clj-client "0.8.606"
:exclusions [org.eclipse.jetty/jetty-http
org.eclipse.jetty/jetty-util
org.eclipse.jetty/jetty-client]]
but that just results in
clojure.lang.Compiler$CompilerException: java.lang.ClassNotFoundException: org.eclipse.jetty.client.HttpClient, compiling:(cognitect/http_client.clj:1:1)
Any help would be greatly appriciated.
PS. I'm a newbie to clojure, and these error messages are just impossible to understand
Try not to use jetty. Someone from the Slack group who came up with a very similar problem now uses this combination (http-kit in place of jetty):
[com.datomic/datomic-free "0.9.5544"] [ring/ring-core "1.5.0"] [http-kit "2.2.0"]
I ran into this issue too and could find no workaround. From what I understand it looks like ring-core is using an older jetty adapter for legacy purposes. I've found https://github.com/sunng87/ring-jetty9-adapter a worthy replacement as a ring dependancy so far with no further issues in my setup:
[com.datomic/clj-client "0.8.606" :exclusions [org.eclipse.jetty/jetty-http org.eclipse.jetty/jetty-util org.eclipse.jetty/jetty-client]]
[info.sunng/ring-jetty9-adapter "0.10.0"]
It's odd. The :exclusion worked for me(but I see it did not work for you). It's documented here
[com.datomic/client-pro "0.8.28"
:exclusions [org.eclipse.jetty/jetty-client
org.eclipse.jetty/jetty-http
org.eclipse.jetty/jetty-util]]

cannot run ring with lein

I am trying my first run with ring and lein, and I am facing problems in getting it to run. I have taken this example from the book "Web development with Clojure", chapter 1, and also from https://quickleft.com/blog/your-first-clojure-web-app/ . The code from both these sites give me the same error - Class Not Found.
I have the following project.clj
(defproject myfirstwebapp "0.1.1"
:description "A hello world for a Ring based web app"
:dependencies [[org.clojure/clojure "1.8.0"]
[ring "1.4.0"]]
:plugins [[lein-ring "0.9.7"]]
:dev-dependencies [[lein-ring "0.9.7"]]
:ring {:handler myfirstwebapp.core/app})
And the following core.clj
(ns myfirstwebapp.core)
(defn app [req]
{:status 200
:headers {"content-Type" "text/html"}
:body "Hello World!"})
And the commands I ran were these:
lein new myfirstwebapp
edit project.clj as above
cd myfirstwebapp
lein deps
edit src/myfirstwebapp/core.clj as above
lein ring server
And now I am getting errors like:
Exception in thread "main" java.lang.ClassNotFoundException: leiningen.core.project$reduce_repo_step, compiling:(C:\Users\ROG\form-init7789757414629005682.clj:1:17608)
Is there some mismatch between the versions of different components that I am using? Or something else?
It is a bug in lein 2.6.0. Fixed in 2.6.1

Clojure failing to compile jackknife

As a clojure noob, I am trying to use cascalog to parse a large CSV file. Here is my minimal project.clj:
(defproject org.example/sample "1.0.0-SNAPSHOT"
:description "extract fields from a certain csv file."
:dependencies [
[cascalog "2.0.0"]
[clojure-csv/clojure-csv "2.0.1"]
]
:profiles { :dev {:dependencies [[org.apache.hadoop/hadoop-core "1.1.2"]]}}
:jvm-opts ["-Xms768m" "-Xmx768m"]
)
lein deps succeeds, but when I run (use 'cascalog.api) inside lein repl, then I get the following error:
CompilerException java.lang.RuntimeException: Unable to resolve symbol: combinations in this context, compiling:(jackknife/seq.clj:12)
Removing clojure-csv from project.clj prevents the error, but I can run (use 'clojure-csv.core) inside lein repl without error.
One other person on the internet appears to have had this problem, but has not posted a solution. What is going on here, and how should I fix it? I'd be eternally grateful if someone could help.