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.
Related
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.
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))
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
I'm trying to run a basic test with
https://github.com/cemerick/clojurescript.test
I've created a simple project such as:
(defproject sampleproj "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/clojurescript "0.0-2014"]
]
:plugins [[lein-cljsbuild "1.0.0"]
[com.cemerick/clojurescript.test "0.2.2"]]
:cljsbuild {:builds [{:source-paths ["src-js" "test-js"]
:compiler {:output-to "target/cljs/testable.js"
:optimizations :whitespace
:pretty-print true}}]
:test-commands {"unit-tests" ["phantomjs" :runner
"this.literal_js_was_evaluated=true"
"target/cljs/testable.js"]}}
)
Both folders src-js and test-js exist since I intend to put all my clojurescript files there.
In my test-js/sampleproj folder I copied the sample test in the documentation:
(ns sampleproj.sampletest
(:require-macros [cemerick.cljs.test
:refer (is deftest with-test run-tests testing test-var)])
(:require [cemerick.cljs.test :as t]))
(deftest somewhat-less-wat
(is (= "{}[]" (+ {} []))))
(deftest javascript-allows-div0
(is (= js/Infinity (/ 1 0) (/ (int 1) (int 0)))))
(with-test
(defn pennies->dollar-string
[pennies]
{:pre [(integer? pennies)]}
(str "$" (int (/ pennies 100)) "." (mod pennies 100)))
(testing "assertions are nice"
(is (thrown-with-msg? js/Error #"integer?" (pennies->dollar-string 564.2)))))
Now if I try to run the tests
-> % lein cljsbuild test
Compiling ClojureScript.
Running ClojureScript test: unit-tests
ReferenceError: Can't find variable: cemerick
phantomjs://webpage.evaluate():2
phantomjs://webpage.evaluate():5
phantomjs://webpage.evaluate():5
ReferenceError: Can't find variable: cemerick
phantomjs://webpage.evaluate():2
phantomjs://webpage.evaluate():5
phantomjs://webpage.evaluate():5
Subprocess failed
I'm fairly new to clojurescript so probably I'm missing something.
Update:
My environment
-> % lein -v
Leiningen 2.3.4 on Java 1.7.0_06 Java HotSpot(TM) 64-Bit Server VM
-> % phantomjs -v
1.9.2
-> % java -version
java version "1.7.0_06"
Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
Java HotSpot(TM) 64-Bit Server VM (build 23.2-b09, mixed mode)
Are macros located right into clj sources ?
After that th compiler shoud compiler you cemeric macros to javascript.
You propably have dependencies right in project.clj
This hasn't been answered, so I will. You need to specify your dependency for clojurescript.test : [com.cemerick/clojurescript.test "0.3.1"]
I'm hacking on a Clojure app I created with lein new app inclojure. There are a few things I'd like to pre-load every time I fire up the REPL, so I created a dev/user.clj file, and source it in my project.clj:
(defproject inclojure "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"]]
:main ^:skip-aot inclojure.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}
:dev {:source-paths ["dev"]}})
The file mostly just requires a bunch of crap so I can use shorthand:
(ns inclojure.core
(:require [clojure.java.io :as io]
[clojure.tools.namespace.repl :refer (refresh-all)])
(:use [clojure.reflect :only [reflect]]
[clojure.pprint :only [pprint print-table pp]]))
(defn r
"inspect all of the properties in a java object, optionally by specifying a
pattern"
([o] (r o "."))
([o prefix]
(->> (reflect o :ancestors true)
:members
(filter #(re-find (re-pattern (str "(?i)" prefix)) (str (:name %))))
(pprint))))
This all works, but when I run (refresh-all), it loses everything from dev/user.clj. Is there a way for me to be able to (refresh-all) from the and either keep or re-load everything from dev/user.clj?
It seems like I may want to create a REPL-specific namespace like inclojure.repl in dev/user.clj, and then make that the REPL's init-ns.