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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.