leiningen clj-time dependencies in Eclipse getting namespace not found exception - eclipse

I'm using leiningen in Eclipse. I can't seem to load the clj-time libraries.
Here's my project.clj:
(defproject MatchAnal "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"}
:keep-non-project-classes true
:dependencies [[org.clojure/clojure "1.5.1"] [clj-time "0.5.1"]])
I clicked on Leiningen -> Update Dependencies in my project and I can see the clj-time-0.5.1.jar in the Leiningen dependencies tree.
When I try to use clj-time from the repl or in a namespace I get a namespace not found excpetion. For example if I type this in the repl:
(use 'clj-time.core)
I get:
Exception namespace 'clj-time.core' not found clojure.core/load-lib (core.clj:5380)

According to the comments, I'm posting the answer here:
Try to remove :keep-non-project-classes and then try lein clean and then lein deps and see whether it is going to work.

Related

current session error opening REPL in emacs with CIDER

I've been following a tutorial and hit an error where there wasn't one in the book. I have reinstalled leinigen, updated java and reinstalled cider on emacs.
But doesn't seem to help and I can't find this error message online. Running M-x "cider-jack-in" to open a REPL gives me the error message:
"Symbol’s function definition is void: sesman-current-sessions"
and I can't figure out what's causing this, any help is gratefully received.
I ran into the same problem. It's possible that you're using an old version of the sesman package. Updating cider for me didn't update the sesman dependency.
For example, sesman-20180903.1826 doesn't define sesman-current-sessions while sesman-20181109.1100 does. Updating sesman fixed the issue for me.
Can you post your project.clj file? Maybe it contains old versions of libraries that are either conflicting with the newest CIDER.
A typical minimal project.clj from a fresh new project created with lein new app myapp will look like this:
(defproject myapp "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.9.0"]]
:main ^:skip-aot overflow.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})

How do use jMusic (a Java library) with Clojure?

I've decided I want to use Clojure's Java interoperability to play with the jMusic library. Because I know Java better than Clojure (by a lot), I'm testing things in Java and then rewriting them as (not-so-idiomatic) Clojure. I'm using Eclipse Luna with the Counterclockwise plugin, and am not using Maven, just Leiningen. As a quick aside, I don't want to use Emacs because I want to focus on learning one tool at a time.
To incorporate jMusic, I've downloaded the file and am right-clicking on the Project folder, selecting Build Path, and selecting Add External Archive. I've done that with both the Clojure project and the Java project. I have the following Java code:
import jm.music.data.Note;
import jm.util.Play;
public final class TestMusic {
public static void main(String[] args) {
Play.midi(new Note());
}
}
This program runs and makes noise without issue. I cannot reproduce this in Clojure. I wrote the following code (which could be wrong, but that's a separate issue):
(ns my-clojure-test.core
(:use jm.music.data Note)
(:use jm.util Play))
(. Play midi (. Note))
And I get the following error:
;; Clojure 1.6.0
CompilerException java.io.FileNotFoundException: Could not locate jm/music/data__init.class
or jm/music/data.clj on classpath: , compiling:(my_clojure_test/core.clj:1:1)
#<Namespace my-clojure-test.core>
I've tried doing the same right-click on the project and adding an external archive. I've moved the jMusic.jar to src/java, and also extracted its files alongside the .jar.
My project.clj file looks like this:
(defproject my-clojure-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.6.0"]
[org.clojure/core.logic "0.8.10"]]
:source-paths ["src" "src/my-clojure-test"]
:java-source-paths ["src/java"])
How do I get Clojure to recognize the jMusic so I can make the aural "hello world" program play?
EDIT:
The selected answer does work, but do check the comments for more details about what I had to do to get it working, in case anyone else runs into the same problem.
To break down the error message:
CompilerException java.io.FileNotFoundException: Could not locate jm/music/data__init.class
or jm/music/data.clj on classpath: , compiling:(my_clojure_test/core.clj:1:1)
#<Namespace my-clojure-test.core>
This is saying that it was looking for either jm/music/data__init.class or jm/music/data.clj. Either one would suffice in order to load the namespace jm.music.data which you have asked for in your ns declaration. Of course there is no such Clojure namespace. This happened because you tried to use use to access classes, and it is designed for accessing namespaces. import is for accessing classes and packages.
(ns my-clojure-test.core
(:import (jm.music.data Note)
(jm.util Play)))
The . notation takes a method first, then the class, except when accessing a static method, in which case one should use /. The proper way to invoke a constructor is with the . following the classname, without any separator.
(Play/midi (Note.))

lein ring server with nrepl doesn't honour cider-nrepl

When I start up my current project with lein ring server and try to connect to it from Emacs via cider, I get the following warning:
; CIDER 0.8.2 (Java 1.7.0_51, Clojure 1.6.0, nREPL 0.2.6)
WARNING: The following required nREPL ops are not supported:
apropos classpath complete eldoc info inspect-start inspect-refresh inspect-pop inspect-push inspect-reset macroexpand ns-list ns-vars resource stacktrace toggle-trace-var toggle-trace-ns undef
Please, install (or update) cider-nrepl 0.8.2 and restart CIDER
user>
However, I do have a dependency for [cider/cider-nrepl "0.8.2"] in my project.clj. This is working just fine when I run lein repl and to which I can then connect just fine from cider:
; CIDER 0.8.2 (Java 1.7.0_51, Clojure 1.6.0, nREPL 0.2.6)
swedishchef.handler>
I can see that I get two different messages from leiningen wrt. nREPL, depending on how I start:
[sugarcube->swedishchef]lein ring server
See https://github.com/technomancy/leiningen/wiki/Repeatability)
Started nREPL server on port 44231
This is the output with the working cider-nrepl connection:
[sugarcube->swedishchef]lein repl
See https://github.com/technomancy/leiningen/wiki/Repeatability)
nREPL server started on port 38024 on host 127.0.0.1 - nrepl://127.0.0.1:38024
REPL-y 0.3.5, nREPL 0.2.6
Looking at the output of lein deps :tree I don't see any problems. So, my first question is whether this supposed to work, i.e., if cider-nrepl should override lein rings behavior wrt. to nrepl startup? If so, could somebody give some advice for further troubleshooting?
Use latest lein-ring plugin version 0.9.2 and add :nrepl-middleware containing vector of nrepl-middlewares to :repl-options in your project.clj
For example, I create the project by lein new compojure-app my-app. Then, I tested it by creating a empty leiningen profile in ~/.lein/profiles.clj ex. {:yolo {}} and starting ring server by lein with-profile yolo,dev ring server.
(defproject my-app "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.6.0"]
[compojure "1.1.6"]
[hiccup "1.0.5"]
[ring-server "0.3.1"]
[cider/cider-nrepl "0.8.2"]]
:plugins [[lein-ring "0.9.2"]]
:ring {:handler my-app.handler/app
:init my-app.handler/init
:destroy my-app.handler/destroy
:nrepl {:start? true}}
:repl-options {:nrepl-middleware
[cider.nrepl.middleware.apropos/wrap-apropos
cider.nrepl.middleware.classpath/wrap-classpath
cider.nrepl.middleware.complete/wrap-complete
cider.nrepl.middleware.info/wrap-info
cider.nrepl.middleware.inspect/wrap-inspect
cider.nrepl.middleware.macroexpand/wrap-macroexpand
cider.nrepl.middleware.ns/wrap-ns
cider.nrepl.middleware.resource/wrap-resource
cider.nrepl.middleware.stacktrace/wrap-stacktrace
cider.nrepl.middleware.test/wrap-test
cider.nrepl.middleware.trace/wrap-trace
cider.nrepl.middleware.undef/wrap-undef]}
:profiles
{:uberjar {:aot :all}
:production
{:ring
{:open-browser? false, :stacktraces? false, :auto-reload? false}}
:dev
{:dependencies [[ring-mock "0.1.5"] [ring/ring-devel "1.3.1"]]}})

clojure: profiles.clj not getting honored in some projects when using cider

I'm facing the same issue that is mentioned in the last comment in https://stackoverflow.com/a/25401281/4329629 (by Yu Shen)
I don't know why adding :plugins [[cider/cider-nrepl "0.7.0"]] at
~/.lein/profiles.clj does not work. But the same expression: :plugins
[[cider/cider-nrepl "0.7.0"]] at the project.clj of my project worked
as expected.
Till now i thought that all my projects were behaving this way, but today i found something different. Maybe a hint to what is going wrong? The 2 projects that behave differently have the following structure:
==================== project-1/project.clj (cider does not work) ====================
(defproject clj "0.1.0-SNAPSHOT"
:description "Frontend for stox#gryffin"
:url "http://stox.gryff.in/"
:dependencies [[selmer "0.6.9"]
[clj-time "0.6.0"]
[http-kit "2.1.18"]
[com.taoensso/timbre "3.2.1"]
[noir-exception "0.2.2"]
[im.chit/cronj "1.4.3"]
[environ "1.0.0"]
[org.clojure/tools.nrepl "0.2.3"]
[clojure-complete "0.2.4"]
[org.clojure/clojure "1.6.0"]
[org.clojure/data.json "0.2.5"]
[ring-server "0.3.1"]
[com.taoensso/tower "2.0.2"]
[com.novemberain/monger "2.0.0"]
[org.clojure/math.numeric-tower "0.0.4"]
[lib-noir "0.8.4"]]
:jvm-opts ["-Xmx512m" "-Xms128m"]
:plugins [[lein-environ "1.0.0"]]
:main clj.core)
==================== project-2/project.clj (cider works) ====================
(defproject project-euler "0.1.0-SNAPSHOT"
:description "Solve problems on project-euler website"
:url "http://projecteuler.net/problems"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/core.memoize "0.5.6"]
[expectations "2.0.13"]
[org.clojure/math.numeric-tower "0.0.4"]
[org.clojure/math.combinatorics "0.0.8"]
[criterium "0.4.3"]
[org.clojure/tools.trace "0.7.8"]
[com.taoensso/timbre "3.2.1"]]
:plugins [[lein-autoexpect "1.0"]])
==================== ~/.lein/profiles.clj ====================
{:user {:plugins [[cider/cider-nrepl "0.9.0-SNAPSHOT"]]}}
EDIT:
1. error message seen in cider for project-1
; CIDER 0.9.0alpha (package: 20150114.512) (Java 1.7.0_55, Clojure 1.6.0, nREPL 0.2.6)
WARNING: The following required nREPL ops are not supported:
apropos classpath complete eldoc info inspect-start inspect-refresh inspect-pop inspect-push inspect-reset macroexpand ns-list ns-vars resource stacktrace toggle-trace-var toggle-trace-ns undef
Please, install (or update) cider-nrepl 0.9.0-SNAPSHOT and restart CIDER
WARNING: CIDER's version (0.9.0-snapshot) does not match cider-nrepl's version (not installed)
(snipped) lein deps :tree
warn
[cider/cider-nrepl "0.9.0-20150118.121230-2"]
[cljs-tooling "0.1.3" :exclusions [[org.clojure/clojure]]]
[compliment "0.2.1-20141130.115631-1" :exclusions [[org.clojure/clojure]]]
[defprecated "0.1.1"]
[org.clojure/java.classpath "0.2.0" :exclusions [[org.clojure/clojure]]]
[org.clojure/tools.trace "0.7.8" :exclusions [[org.clojure/clojure]]]
[org.tcrawley/dynapath "0.2.3" :exclusions [[org.clojure/clojure]]]
$ lein version
Leiningen 2.5.1 on Java 1.8.0_25 OpenJDK 64-Bit Server VM
My ~/.lein/profiles.clj:
{:user {:plugins [[cider/cider-nrepl "0.9.0-SNAPSHOT"]]
:dependencies [[org.clojure/tools.nrepl "0.2.7"]]}}
(exactly as https://stackoverflow.com/a/15172955/1047788 suggests)
Running lein repl in an empty directory:
$ lein repl
nREPL server started on port 40595 on host 127.0.0.1 - nrepl://127.0.0.1:40595
REPL-y 0.3.5, nREPL 0.2.6
Clojure 1.6.0
OpenJDK 64-Bit Server VM 1.8.0_25-b18
Docs: (doc function-name-here)
after creating a project with lein new app; cd app
$ lein repl
Retrieving org/clojure/clojure/1.6.0/clojure-1.6.0.jar from central
nREPL server started on port 55421 on host 127.0.0.1 - nrepl://127.0.0.1:55421
REPL-y 0.3.5, nREPL 0.2.7
Clojure 1.6.0
I am inclined to believe this might be a manifestation of some bug i Leiningen, but I am not sure... (why is it downloading clojure?)
UPDATED MAY/2021
Change your ~/.lein/profiles.clj file to the following:
{:user {:plugins [[cider/cider-nrepl "0.26.0-SNAPSHOT"]]
:dependencies [[nrepl "0.8.3"]]}}
Dependency specification for nrepl is referenced from cider-nrepl Clojars page.

incanter charts cannot be found

I build a new project using leiningen to test incanter:
lein new testincanter
Then, in project.clj, I put this:
(defproject testincanter "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"]
[incanter "1.5.4"]])
Then I start the repl:
lein repl
everything is good.
Then I do this,
(ns testincanter.sample
(:use (incanter core datasets io optimize charts stats)))
Then it returns exceptions like:
java.lang.Exception: namespace 'incanter.charts' not found
or
clojure.lang.Compiler$CompilerException: java.lang.NoSuchFieldException: createIntegerTickUnits
I have tried incanter.core, incanter.datasets, incanter.io... separately,
all work well, except incanter.charts