I use riemann and now I write my riemann.config.
I want to use clj-http post all events from riemann stream to my web server. But I don't know how to import clj-http from riemann.jar.
I code (:use clj-http.client) or (:require [clj-http.client :as client]) in riemann.config but got error:
java.lang.ClassNotFoundException: clj-http.client
Could anyone help me ?
I did something similar few months ago and this was working for me. I was using http-kit :
(require '[org.httpkit.client :as http])
Since both http-kit and cli-http are available in riemann ( see https://github.com/aphyr/riemann/blob/master/project.clj ) You should be able to require cli-http the same way :
(require '[clj-http.client :as client])
Problem in your configuration is that you are using (:use ... an (:require .... which is supposed to be used within the namespace declaration. Since riemann.config doesn't contain namespace declaration you can't use these forms. When calling
(:use clj-http.client)
you get ClassNotFoundException because clojure is trying to invoke function :use on clj-http.client , which can't be found. Outside the namespace declaration :use is just a standard keyword with no special meaning.
Related
What is the difference between core & inope?
I have a very brief idea that core is like the main equivalent in Java. And inope is like an interface between java and clojure, although I dont understand the purpose of inope entirely.
I found this in a project and this is my understanding:
inope.clj is used for writing java clojure interoperable functions.
The namespace contents imply that it functions like core.clj here.
in this inope.clj file, they have imported dependencies and defined java-clojure interoperable functions in gen-class as such :
(ns prject-avon.inope
(:require [prject-avon.ioutil :as utl]
[aero.core :as aero-core :refer (read-config)]
[clojure.java.data :as clj-data]
[malli.core :as m]
[malli.util :as mu]
[malli.instrument :as mi]
[malli.error :as me]
[malli.json-schema :as json-schema]
(:gen-class
:methods [ ^{:static true} [validateData [Object String] Boolean]
]))
<Functions are defined here>
Those are just names, there's no significance to them. In particular, I've never heard of inope myself. The only way you can reliably judge is by the namespace's contents and their usage. It's also very possible that a single namespace contains all sorts of unrelated stuff.
I have a file in my project where I define a few protocols and records (defprotocol and defrecord).
I'm trying to use them in a different file/namespace like this:
(ns myapp.core
(:require [myapp.protocols :refer [SomeProtocol]]))
This causes an Execution error (IllegalAccessError) at .... Does anyone know why?
btw, doing :refer :all does work but I don't want to bring in several unneeded symbols into the namespace.
thanks
New clojure developer trying to experiment with the HTTP kit clojure library in a REPL.
I created a new project in leinengen, lein new app kit-expt.
Then I modified the :dependencies block in project.clj to include [http-kit "2.2.0"].
Then I run lein deps, then lein repl.
In the REPL I try to run (:require [org.httpkit.client :as http]).
However, when I run this I get the error
CompilerException java.lang.ClassNotFoundException: org.httpkit.client, compiling:(/private/var/folders/cs/b0kcg6fx0335crbvn6xtgq7xl5c29j/T/form-init7575648818353088270.clj:1:1)
What am I doing wrong?
The :require form you're using is invalid, a keyword only for use in an ns (namespace) form. Try removing the : and just use (require ..., which is commonly used in a REPL. See more require examples here.
The HTTP Client docs you refer to assume you're in a source file using ns.
There appears to be something wrong in your environment. If I run it (Ubuntu 16.04) it works great:
(require '[org.httpkit.client :as http])
(pr-str (clojure.core/deref (http/get "http://google.com"))))
=> "{:opts {:method :get, :url \"http://www.google.com/\", :query-params nil, :form-params nil, :trace-re".....
Update
As Micah pointed out, in the repl you need the above form of require. Notice that it doesn't have the leading colon, and it does have a single-quote before the left square bracket. It must also be inside parentheses instead of square brackets.
In the ns form (which I prefer), everything has the opposite convention:
(ns tst.clj.core
(:use clj.core clojure.test tupelo.test)
(:require
[tupelo.core :as t]
[org.httpkit.client :as http] ))
As simple as this question is, I can't seem to find the right way for different namespaces in the same directory to validly refer to one another. I have two files:
project_root/src/babbler/core.clj:
(ns babbler.core
(:gen-class)
(use '[clojure.string :only (join split)]))
(defn foo [] "Foo")
and then project_root/src/babbler/bar.clj:
(ns babbler.bar)
(use [babbler.core :as babble])
This file also contains a main method, which is specified in my project.clj via :main babbler.bar
My entire structure is that generated by counterclockwise, with with default leiningen template.
The result of running lein repl is this:
Exception in thread "main" java.lang.ClassNotFoundException: babbler.core, compiling:(babbler/bar.clj:3:1)
at clojure.lang.Compiler.analyze(Compiler.java:6380)
at clojure.lang.Compiler.analyze(Compiler.java:6322)
at clojure.lang.Compiler$VectorExpr.parse(Compiler.java:3024)
at clojure.lang.Compiler.analyze(Compiler.java:6363)
at clojure.lang.Compiler.analyze(Compiler.java:6322)
(...)
Your use should be inside the definition of the namespace:
(ns babbler.bar
(use [babbler.core :as babble]))
In fact use is discouraged, you may want to write it as:
(ns babbler.bar
(:require [babbler.core :as babble :refer [foo]]))
That way you can call any function f from the babbler.core namespace as babble/f, and you can call foo directly. In addition, your file has information about where foo comes from so you or someone else won't need to go searching for it.
I'm trying to use -?> in Clojure but get the error:
Caused by: java.lang.RuntimeException: Unable to resolve symbol: -?> in this context
What do I need to import in order to use it?
First of all, you need to add a dependency on core.incubator to your project.clj (if you aren't using leiningen, that should be your first step):
:dependencies [...
[org.clojure/core.incubator "0.1.1"]]
Next, you can use it in your code like this:
(ns myapp.core
(:use [clojure.core.incubator :only [-?>]]))
If you're using Clojure 1.4, this will also work:
(ns myapp.core
(:require [clojure.core.incubator :refer [-?>]]))
And is preferable if you don't plan to support Clojure pre-1.4 versions of Clojure.