LightTable not connecting/evalling a Clojure project - clojure

Just starting a new Clojure project and running into some issues getting LightTable to play nicely. The app/REPL spin up fine with lein ring server / lein repl etc, but trying to connect to any file in LightTable just keeps the blue spinner…spinning…even after it says it's connected.
These are my deps (with LightTable 1.5.4 - just updated from 1.4.something which was doing the same thing)
(defproject clollo "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.5.1"]
[compojure "1.1.5"]
[trello "0.1.1-SNAPSHOT"]]
:plugins [[lein-ring "0.8.5"]]
:ring {:handler clollo.handler/app}
:profiles
{:dev {:dependencies [[ring-mock "0.1.5"]]}})
Files in question are
(ns clollo.handler
(:use compojure.core)
(:require [compojure.handler :as handler]
[compojure.route :as route]
[trello.core]))
(defroutes app-routes
(GET "/" [] "Hello Wo1rld")
(route/resources "/")
(route/not-found "Not Found"))
(def app
(handler/site app-routes))
(+ 1 1) ;; test LightTable eval!
I then tried getting rid of all the requires etc for debugging, so I have a new file
(ns clollo.ihopethisworks)
(+ 1 1) ;; this doesn't work either
Any ideas? As I say, LightTable's InstaRepl works fine on its own, and LightTable is connecting to this project's project.clj in the connect window. Just spinning when it tries to eval anything.
Thanks!

From testing your sample code, it looks like the [trello.core] require item, in the handler.clj file, is causing the issue. The library seems to have an issue with initializing clj-http in Light Table.
Also, there is an issue, with LT v0.5.x, where the working indicator, in some cases, keeps spinning after the operation is complete. You can use the Statusbar: Reset working indicator command to stop it.

Related

Using lein ring server, how to switch to another adapter than ring-jetty-adapter

Given a simple webapplication like
(ns webtest.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]))
(defroutes app-routes
(GET "/" [] "Hello World")
(route/not-found "Not Found"))
(def app
(-> (wrap-defaults app-routes site-defaults)))
that can be started using lein ring server, how would one be able to adapt the project to switch out the jetty adapter for another ring adapter, for instance undertow or http-kit?
For reference, here's the excerpt of the lein project.clj in use:
:dependencies [[org.clojure/clojure "1.9.0"]
[ring "1.8.1" :exclusions [ring/ring-jetty-adapter]]
[luminus/ring-undertow-adapter "1.1.0"]
[ring/ring-defaults "0.3.2"]
[compojure "1.6.1"]]
:plugins [[lein-ring "0.12.5"]]
:ring {:handler webtest.handler/app}
You can use :adapter key.
Finally I tested and no, the tag :adapter allows to pass the options for ring.jetty.adapter only.
After analyse the source code, there is no possibility to switch the adapter.
Here an reponse from the plugin author to a similar query:
https://stackoverflow.com/a/24307363/5773724

cannot run ring with lein

I am trying my first run with ring and lein, and I am facing problems in getting it to run. I have taken this example from the book "Web development with Clojure", chapter 1, and also from https://quickleft.com/blog/your-first-clojure-web-app/ . The code from both these sites give me the same error - Class Not Found.
I have the following project.clj
(defproject myfirstwebapp "0.1.1"
:description "A hello world for a Ring based web app"
:dependencies [[org.clojure/clojure "1.8.0"]
[ring "1.4.0"]]
:plugins [[lein-ring "0.9.7"]]
:dev-dependencies [[lein-ring "0.9.7"]]
:ring {:handler myfirstwebapp.core/app})
And the following core.clj
(ns myfirstwebapp.core)
(defn app [req]
{:status 200
:headers {"content-Type" "text/html"}
:body "Hello World!"})
And the commands I ran were these:
lein new myfirstwebapp
edit project.clj as above
cd myfirstwebapp
lein deps
edit src/myfirstwebapp/core.clj as above
lein ring server
And now I am getting errors like:
Exception in thread "main" java.lang.ClassNotFoundException: leiningen.core.project$reduce_repo_step, compiling:(C:\Users\ROG\form-init7789757414629005682.clj:1:17608)
Is there some mismatch between the versions of different components that I am using? Or something else?
It is a bug in lein 2.6.0. Fixed in 2.6.1

lein run command raises exception

once i added one more namespace in my (toy) project one exception is raised after starting the server:
lein run
I am copying below my project.clj file.
(defproject compoj02 "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"]
[ring "1.3.1"]
[compojure "1.2.1"]
[clout "2.0.0"]
[enlive "1.1.5"]
[org.clojure/data.csv "0.1.2"]
;[org.clojure/data.csv]
]
:main compoj02.core)
The error is
Exception in thread "main" java.io.FileNotFoundException: Could not locate clojure/data/csv__init.class or clojure/data/csv.clj on classpath: , compiling:(compoj02/pompaq.clj:1:1)
at clojure.lang.Compiler.load(Compiler.java:7142)
The new namespace contains one simple function:
(ns compoj02.pompaq
(:require [clojure.data.csv :as csv]
[clojure.data.io :as iov]))
(defn process-csv [file]
(with-open [in-file (iov/reader file)]
(doall
(csv/read-csv in-file))))
thanks for reading!
PS. I am adding few details.I executed the command lein deps. Also, there is a chain of files: core.clj uses a reference to templates.clj and this one uses a reference to the pompaq.clj. When I comment out the declaration (:use compoj02.pompaq) used in the namespace of templates.clj, I am able to start the application via lein run.
Try lein deps to make sure everything is there. Also, without a -main function, your command should be =>
lein run -m compoj02.pompaq/process-csv file-arg-here

How to Run Jetty Example with Ring in Clojure

I am following along with this example on creating a simple web service in Clojure using ring and jetty.
I have this in my project.clj:
(defproject ws-example "0.0.1"
:description "REST datastore interface."
:dependencies
[[org.clojure/clojure "1.5.1"]
[ring/ring-jetty-adapter "0.2.5"]
[ring-json-params "0.1.0"]
[compojure "0.4.0"]
[clj-json "0.5.3"]]
:dev-dependencies
[[lein-run "1.0.0-SNAPSHOT"]])
This in script/run.clj
(use 'ring.adapter.jetty)
(require '[ws-example.web :as web])
(run-jetty #'web/app {:port 8080})
And this in src/ws_example/web.clj
(ns ws-example.web
(:use compojure.core)
(:use ring.middleware.json-params)
(:require [clj-json.core :as json]))
(defn json-response [data & [status]]
{:status (or status 200)
:headers {"Content-Type" "application/json"}
:body (json/generate-string data)})
(defroutes handler
(GET "/" []
(json-response {"hello" "world"}))
(PUT "/" [name]
(json-response {"hello" name})))
(def app
(-> handler
wrap-json-params))
However, when I execute:
lein run script/run.clj
I get this error:
No :main namespace specified in project.clj.
Why am I getting this and how do I fix it?
You're getting this error because the purpose of lein run (according to lein help run) is to "Run the project's -main function." You don't have a -main function in your ws-example.web namespace, nor do you have a :main specified in your project.clj file, which is what lein run is complaining about.
To fix this, you have a few options. You could move the run-jetty code to a new -main function of the ws-example.web function and then say lein run -m ws-example.web. Or you could do that and also add a line :main ws-example.web to project.clj and then just say lein run. Or you could try using the lein exec plugin to execute a file, rather than a namespace.
For more info, check out the Leiningen Tutorial.
You have to put that (run-jetty) stuff into a -main somewhere and then add it to the project.clj like
:main ws-example.core)
From lein help run:
USAGE: lein run -m NAMESPACE[/MAIN_FUNCTION] [ARGS...]
Calls the main function in the specified namespace.
So, you would need to put your script.clj somewhere on the project source path and then call it as:
lein run -m script

Problem using redis-clojure with Leiningen

Hey, I'm new to Clojure and Leiningen and a bit stuck. I've managed to setup a project with Leiningen. I'm able to compile it into an uberjar and run the repl. I've also managed to load a dependency named aleph to run a simple concurrent webserver.
The next step for me is to use redis-clojure to access redis. But here I'm stuck. This is my project.clj:
(defproject alpha "0.0.1-SNAPSHOT"
:description "Just an alpha test script"
:main alpha.core
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[aleph, "0.1.2-SNAPSHOT"]
[redis-clojure "1.2.4"]])
And here is my core.clj: Note that I only added the line (:requre redis) according to the example from redis-clojure.
(ns alpha.core
(:require redis)
(:gen-class))
(use `aleph.core 'aleph.http)
(defn alpha [channel request]
(let [] (enqueue-and-close channel
{:status 200
:header {"Content-Type" "text/html"}
:body "Hello Clojure World!"}))
(println (str request)))
(defn -main [& args]
(start-http-server alpha {:port 9292}))
When I try to run lein repl this happens:
java.io.FileNotFoundException: Could not locate redis__init.class or redis.clj on classpath: (core.clj:1)
Yes, I have run lein deps and the redis-clojure jar is available in my lib directory. I'm probably missing something trivial, but I've been at this issue for a few hours now and not getting any closer to a solution. Thanks!
Namespace redis does not exist. I suppose you need
(:require [redis.core :as redis])
A way to check for available namespaces:
(use 'clojure.contrib.find-namespaces)
(filter #(.startsWith (str %) "redis") (find-namespaces-on-classpath))
This works with more current versions of Clojure, in this example it finds the names of all namespaces that contains the sub string "jdbc":
(map str
(filter
#(> (.indexOf (str %) "jdbc") -1)
(all-ns)))
The result is a sequence, in example:
=>
("clojure.java.jdbc")