How to add the necessary jar file for the classpath used by the project?
The project.clj is copied below:
1 (defproject hbase01 "0.1.0-SNAPSHOT"
2 :description "FIXME: write description"
3 :url "http://example.com/FIXME"
4 :license {:name "Eclipse Public License"
5 :url "http://www.eclipse.org/legal/epl-v10.html"}
6 :dependencies [[org.clojure/clojure "1.6.0"]
7 [clojure-hbase "0.92.4"]])
At the REPL I tried:
user=> (require '[clojure-hbase.core :as hb])
and it answered back:
CompilerException java.lang.NoClassDefFoundError:
org/apache/hadoop/conf/Configuration, compiling:(clojure_hbase/core.clj:1:1)
I found one jar file /usr/local/hbase/lib/hadoop-common-2.2.0.jar where the class is an inner class... but how to add this path to the project?
I have read and tried the lein-localrepo but it did not get installed in the right location, the jar file get installed into the $username/.m2/repository/hadoop-common folder.
You may have already figured this out, but in case anyone else comes looking for this error. You need to include a jar from the Hadoop project with the Configuration class, as HBase has a dependency on it from what I've found.
I had this error with Clojure 1.6.0 and HBase 94.26.
My project.clj includes:
[org.apache.hbase/hbase "0.94.26"]
[org.apache.hadoop/hadoop-core "1.2.1"]
Just run lein deps and you're off to the races.
First thing to note here is that you have conflicting versions of clojure. You specify 1.6.0 and clojure-hbase still requires 1.5.1. This could probably cause the issue you're seeing.
Related
Despite adding the desired dependency to my project.clj file,
(defproject word-tree "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.10.1"]
[org.clojure/clojurescript "1.10.520"]
[clojure-opennlp "0.5.0"] ; <----------------------here
[reagent "0.8.1"]]
...
I am unable to access the functions that the dependency provides.
After referencing the namespace in one of my files,
(ns word-tree.suffix-tree
(:require [clojure.string :as str]
[opennlp.nlp :as nlp])) ; <-----this is the namespace of the dependency
I get this error:
No such namespace: opennlp.nlp, could not locate opennlp/nlp.cljs, opennlp/nlp.cljc, or JavaScript source providing "opennlp.nlp"
The weirdest part is that when I run lein deps :tree the dependency shows up!
$ lein deps :tree
...
[cider/piggieback "0.4.1" :scope "test"]
[cljfmt "0.5.7"]
[rewrite-clj "0.5.2"]
[rewrite-cljs "0.4.3"]
[clojure-complete "0.2.5" :exclusions [[org.clojure/clojure]]]
[clojure-opennlp "0.5.0"] <------------------------------------------------here!!!
[instaparse "1.4.9"]
[org.apache.opennlp/opennlp-tools "1.9.0"]
[figwheel-sidecar "0.5.19" :scope "test"]
...
For my project I really want to use this dependency but it's not working. Any advice would be most welcome. Thanks.
It seems to me the problem is that the library is for Clojure on the JVM only, and you are trying to use it on a ClojureScript project.
No such namespace: opennlp.nlp, could not locate opennlp/nlp.cljs, opennlp/nlp.cljc, or JavaScript source providing "opennlp.nlp"
The compiler tried to look for ClojureScript code (extension .cljs) or compatible with both Clojure and ClojureScript (extension .cljc) or plain JavaScript, but found none.
I was trying to pick up Clojure again, but am stumbling right at the beginning. I downloaded lein, and copied the following project.clj and a hello.clj to be absolutely sure that I have a minimal 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.7.0"]]
:uberjar {:aot :all}
:main hello.core
)
hello.clj:
(ns hello.core
(:gen-class)
)
(defn -main
"This should be pretty simple."
[]
(println "Hello, World!"))
When I run './lein uberjar' I get these warnings:
Warning: specified :main without including it in :aot.
Implicit AOT of :main will be removed in Leiningen 3.0.0.
If you only need AOT for your uberjar, consider adding :aot :all into your
:uberjar profile instead.
Warning: The Main-Class specified does not exist within the jar. It may not be executable as expected. A gen-class directive may be missing in the namespace which contains the main method.
Created .../target/hello-0.1.0-SNAPSHOT.jar
Created .../target/hello-0.1.0-SNAPSHOT-standalone.jar
Trying to run this either with ./lein run or with java -jar ./target/hello-0.1.0-SNAPSHOT-standalone.jar results in exceptions:
Can't find 'hello.core' as .class or .clj for lein run: please check the spelling.
Exception in thread "main" java.io.FileNotFoundException: Could not locate hello/core__init.class or hello/core.clj on classpath., compiling:(/private/var/folders/28/bk6d4xj123b0xvsvk91_1jg80009rn/T/form-init1007755193774766954.clj:1:125)
So what is my problem here?
:uberjar {:aot :all} -> :profiles {:uberjar {:aot :all}}
And move hello.clj into ./src/hello directory and rename it to core.clj
Leiningen downloaded nearly 1GB of jar index information from repo1.maven.org and clojars.org. Why does it need to download that huge amount of information? And is there any way to prevent that?
The directory in question is: ~/.lein/indeces
It contains the following folders:
https___clojars.org_repo_
https___repo1.maven.org_maven2_
The maven.org folder contains 849MB!
Here is my project definition:
(defproject test-project "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"}
:main test-project.core
:dependencies [[org.clojure/clojure "1.6.0"]
[camel-snake-kebab "0.3.1" :exclusions [org.clojure/clojure]]])
Thanks
This content is maintained not by Leiningen itself, but the lein-search plugin. I'd suggest uninstalling it (the plugin, that is) unless you consider its benefits worth the cost in time and storage.
To do so, remove references to lein-search/lein-search or org.clojars.wuschel/lein-search from your ~/.lein/profiles.clj -- or, if this content was created while working in a different project, from the project.clj of that project.
I've just started with Clojure and have never used Java
I understood how to create and run a leiningen project from terminal, but I can't understand how to load libraries in REPL before running commands.
I'm trying to build a simple web scrapler with clj-webdriver; my original file looks like this
(ns prova.core (:gen-class))
(use 'clj-webdriver.taxi)
(set-driver! {:browser :firefox})
(defn -main
[& args]
(to "https://github.com/login")
(input-text "#login_field" "email")
(input-text "#password" "psw")
(click "input[name='commit']")
)
The closest I (think) have got to achieve it was going into the webdriver src folder and try this command
penta#laptop:~/clj-webdriver-master/src/clj_webdriver$ clojure
Clojure 1.4.0
user=> (use 'taxi)
but it returned
FileNotFoundException Could not locate taxi__init.class or taxi.clj on classpath: clojure.lang.RT.load (RT.java:432)
even thou in the same folder the file taxy.clj was indeed present.
So, what is the procedure to run a REPL that can make use of a library functions?
Many thanks
Take a look at the leiningen build tool, install it according to the website's instructions and make a new project.
lein new myproject
cd myproject
Then edit project.clj in which you add clj-webdriver as a dependency:
(defproject myproject "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-webdriver "0.6.0"]])
Then type lein repl and a REPL will spin up with clj-webdriver on the classpath. You should now be able to continue as you did in your example.
I'm new to clojure. I have a jar file I want to play with in a clojure repl, but I've failed to do so with leiningen 2.
I have tried placing the jar file in src/myjar.jar and also in src/org/mydomain/myjar.jar
When I run lein repl I get errors stating that leiningen can not find my artifact, and a reference to a page about repeatability which I do not understand.
Here is my project.clj (with the real name of myjar)
(defproject cljliveordead "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.3.0"]
[org.allen.temporalintervalrelationships/time "0.2" :extension "jar"]])
You can use local jars using the lein-localrepo plugin. Add this line to your project.clj
:plugins [[lein-localrepo "0.4.0"]]
Then install the jar to the local repository using
lein localrepo install <path-to-jar> org.allen.temporalintervalrelationships/time 0.2
You can check that the file is installed by running lein localrepo list and check that lein can resolve the project dependencies using lein deps. If all is well then you can start playing with the jar using lein repl.
Leiningen doesn't like local jars due to its goal of repeatable builds. If this was a real project using a third party closed source jar then the best thing to do is install it in a local Nexus repository and add a reference to that repository to your project.
However, this all seems a bit heavyweight for what you are trying to achieve. If all you want to do is play with the jar in the REPL then create a simple project like this
(defproject clojure-time "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]
[com.cemerick/pomegranate "0.0.13"]])
and use the pomegranate library to add the jar to your classpath manually
(require '[cemerick.pomegranate :as p])
(p/add-classpath "jsr-310-ri-0.6.3.jar")
(javax.time.Instant/now)
and play away.
the hackish way is to just put it into /proiject/path/lib/ and the 'proper' way is to:
add a dependency for it to your project
run lein deps which will print the command for installing the jar to your local maven repo
run the command leiningen gives you with the path to your jar
run lein deps again
I use clojure-csv in a lot of my applications, so make sure the modules referencing clojure-csv were able to build with it, this is what I did:
0) Ran lein new bene-csv
1) Added this to project.clj (after enter lein new bene-csv). The pertinent line is [clojure-csv/clojure-csv "1.3.2"], but it makes sense to show you the whole project.clj for good example's sake.
(defproject bene-csv "1.0.4-SNAPSHOT"
:description "A csv parsing library"
:dependencies [[org.clojure/clojure "1.3.0"]
[clojure-csv/clojure-csv "1.3.2"]
[util "1.0.2-SNAPSHOT"]]
:aot [bene-csv.core]
:omit-source true)
2) Made sure my bene-csv/src/bene_csv/core.clj references clojure-csv.
(ns bene-csv.core
^{:author "Charles M. Norton",
:doc "bene-csv is a small library to parse a .csv file.
Created on March 8, 2012"}
(:require [clojure.string :as cstr])
(:require [util.core :as utl])
(:use clojure-csv.core))
Finally, I ran these commands, so that my main project could reference bene-csv's functions and defs.
lein deps
lein install