Compilation error including clj-time in project - clojure

I have included [clj-time "0.8.0"] in my project.clj. I then refer to clj-time in my namespace like so:
(ns school-finder.tasks
(:require [clj-time.core :as t]))
However when I try and run the project I get the following compilation error:
Exception in thread "main" java.lang.IllegalArgumentException: No single method: second of interface: clj_time.core.DateTimeProtocol found for function: second of protocol: DateTimeProtocol, compiling:(clj_time/coerce.clj:146:64)
What am I doing wrong?

I think this is a known bug: https://github.com/clj-time/clj-time/issues/124
If you just do a lein clean (possibly followed by a lein deps) that should solve it.

It's hard to say where the problem is, so here's a working example:
project.clj:
(defproject hello "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"]
[clj-time "0.8.0"]]
:source-paths ["dev"])
src/hello/core.clj:
(ns hello.core
(:require [clj-time.core :as t]))
(println (t/now))

Related

Clojure Ring wrap-reload is not working

This is my core.clj file
(ns lein-app.core
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.reload :refer [wrap-reload]]))
(use 'ring.adapter.jetty)
(defroutes app
(GET "/" [] "<h1>Hello world</h1>")
(route/not-found "<h1>Not found</h1>"))
(def reloadable-app
(wrap-reload app))
(defn -main
[]
(run-jetty reloadable-app {:port 3000}))
And this is my project.clj
(defproject lein-app "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"]
[compojure "1.5.2"]
[ring "1.5.0"]]
:main lein-app.core)
When I run lein run it starts the server correctly but if I change the GET response to be anything else for example I need to kill the server and restart it.
as indicated in the ring issue#104 the doc is not quite clear.
For wrap-reload (as well for similar functionality in other libs/projects) one has to pass the var itself not the value.
Like so
(wrap-reload #'app)

GUI Using Seesaw

I am trying to make a small window using Seesaw for Clojure. I have created a project "sample" using Leiningen.
lein new app sample
I have made added the dependency in the project file.
(defproject sample "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"] [seesaw "1.4.4"]]
:main ^:skip-aot sample.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
My source file is as follows:
(ns sample.core
(:gen-class)
(:require [seesaw.core :as seesaw]
[seesaw.dev :as dev]))
(def window (seesaw/frame
:title "First Example"
:content "hello world"))
(dev/show-options window)
But when I run it I keep getting an error: clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: No such namespace: dev, compiling:(C:\Users\A\sample\src\sample\core.clj:10:1)
I followed your instructions and it worked fine for me, so long as I left the -main definition in place.

uberwar cannot locate hiccup/core

I am following the tutorial from the below URL:
http://www.xuan-wu.com/2013-09-21-Basic-Web-Application-in-Clojure
but i received one error when i execute :
lein ring uberwar
The error is:
Caused by: java.io.FileNotFoundException: Could not locate hiccup/core__init.class or hiccup/core.clj on classpath:...
What I read on another stackoverflow thread :
Hiccup not working : FileNotFoundException: Could not locate ../as__init.class or ../as.clj on classpath
is related to the required namespace without the :as.
(ns myblog.views
(:require [hiccup.core :refer (html)]
.......
Also I tried to simple 'use' it:
(ns myblog.views
(:use hiccup.core)
(:require [hiccup.form :as f]
.......
but i received the same error.
What is wrong in my code? Thanks in advance for any hint/url!
I am copying below the project.clj file:
(defproject dgblog "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.6.0"]
[compojure "1.1.9"]
[org.clojure/java.jdbc "0.3.0-alpha5"]
[mysql/mysql-connector-java "5.1.25"]
[ring-basic-authentication "1.0.2"]]
:plugins [[lein-ring "0.8.12"]]
:ring {:handler dgblog.handler/app}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring-mock "0.1.5"]]}})
and the views.clj header :
(ns dgblog.views
(:use hiccup.core)
(:require
;; (:require [hiccup.core :refer (html)]
[hiccup.form :as f]
[dgblog.posts :as posts]))

What is wrong with (use 'korma.db) directive?

When I try to create an uberjar using lein with the following very simple Clojure test file, I get an error
Compiling korma-test.core
Exception in thread "main" java.lang.Exception:
lib names inside prefix lists must not contain periods, compiling:(core.clj:1:1)
and cannot figure out why. I got the (use 'korma.db) from sqlkorma.com's docs section, and tried a require statement as well (not listed in my examples here).
project.clj
(defproject korma-test "0.1.0-SNAPSHOT"
:description "korma db test"
: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"]
[korma "0.3.0-RC5"]]
:main korma-test.core)
core.clj (simplified)
(ns korma-test.core
(:gen-class)
(use 'korma.db)
(require '[clojure.string :as str])
(:import java.util.Date)
)
(defn -main
[& args]
(let [opts (parse-opts args)
start-time (str (Date.))]))
The ns macro uses keywords in place of functions and does take quoted arguments.
(ns korma-test.core
...
(:use korma.db)
(:require [clojure.string :as str])
...)
There is a nice write-up here: http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html

Clojure's :require and Instaparse

I am trying to use instaparse lib for my clojure project. I use leiningen 2.0 and clojure 1.5.1 in my project dependencies. I add instaparse to my project dependencies as follow:
(defproject bachelor "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/clojure-contrib "1.2.0"]
[instaparse "1.1.0"]])
And that is my source where i'm trying to require that lib:
(ns bachelor.data
(:require [clojure.string :as str])
(:require [instaparse.core :as insta])
(:use [clojure.contrib.generic.math-functions])
)
When I try to compile that I get following error message:
cd c:/bachelor/src/bachelor.data/ 1 compiler notes:
Unknown location: error: java.io.FileNotFoundException: Could not
locate instaparse/core__init.class or instaparse/core.clj on
classpath:
company.clj:1:1: error: java.io.FileNotFoundException: Could not
locate instaparse/core__init.class or instaparse/core.clj on
classpath: (company.clj:1)
Compilation failed.
I checked classpath for my project and I think that instaparse should be found there.
lein classpath
C:\bachelor\test;C:\bachelor\src;C:\bachelor\dev-resources;C:\bachelor\resources;C:\bachelor\target\classes;C:\Users\Maciej.m2\repository\instaparse\instaparse\1.1.0\instaparse-1.1.0.jar;C:\Users\Mac
iej.m2\repository\org\clojure\clojure-contrib\1.2.0\clojure-contrib-1.2.0.jar;C:\Users\Maciej.m2\repository\org\clojure\clojure\1.5.1\clojure-1.5.1.jar
Have any idea what I am doing wrong?
UPDATE
I updated result for lein classpath. Earlier, I've pasted old result.
here is a working sample project:
project.clj:
(defproject parse "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"]
[instaparse "1.1.0"]])
you don't need the lines for contrib, and string is built into clojure now.
src/parse/core.clj:
(ns parse.core
(:require [instaparse.core :as insta]
[clojure.string :as str]))
(def as-and-bs
(insta/parser
"S = AB*
AB = A B
A = 'a'+
B = 'b'+"))
repl:
#<Namespace parse.core>
parse.core> (as-and-bs "aaaaabbbaaaabb")
[:S [:AB [:A "a" "a" "a" "a" "a"] [:B "b" "b" "b"]] [:AB [:A "a" "a" "a" "a"] [:B "b" "b"]]]
parse.core> (str/join "," ["a" "b" "c"])
"a,b,c"
My general Liningen strangeness resolution checklist:
run lein deps and restart nrepl/emacs
lein clean and restart nrepl/emacs
remove the local libs dir (lein v1.x)
remove my local maven repository and run lein deps
I've found out what was wrong. I was creating project with leiningen but develop source with Clojure-box or Clooj. I was also trying to compile my source with that tools and it was mistake. When you run such IDE it loads that's own classpath and that is why it could not find library I'd like to use. Now I compile my src with
lein compile
and run it in
lein repl
and everything is just working fine.