Clojure "already refers to" exception for Hiccup's with-base-url - clojure

I am going through Liberator's Getting Started guide. At the very beginning, when trying to evaluate the above namespace declaration
(ns restserver.core
(:require [liberator.core :refer [resource defresource]]
[ring.middleware.params :refer [wrap-params]]
[compojure.core :refer [defroutes ANY]]))
i get
;!!CompilerException java.lang.IllegalStateException: with-base-url already refers to: #'hiccup.core/with-base-url in namespace: hiccup.page, compiling:(hiccup/page.clj:1:1)
List of declared dependencies in project.clj looks like this:
:dependencies [[org.clojure/clojure "1.7.0"]
[liberator "0.13"]
[compojure "1.4.0"]
[org.apache.storm/storm-core "0.9.5"]
[org.clojure/data.json "0.2.6"]
[ring "1.4.0"]]
It seems that storm-core dependency is causing this issue, as when i remove it, the problem is gone. How can i fix this problem? (apart from moving Storm-related code to a separate library)?
UPDATE: there is an issue on Storm project JIRA posted for exactly this problem.

Try excluding hiccup from the storm-core by providing exclusions on project.clj:
:dependencies [[org.clojure/clojure "1.7.0"]
[liberator "0.13"]
[compojure "1.4.0"]
[org.apache.storm/storm-core "0.9.5" :exclusions [hiccup]]
[org.clojure/data.json "0.2.6"]
[ring "1.4.0"]]

Related

Adding dependencies to clojure projects using lein

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.

Could not locate clojure/data/xml__init.class in a luminus project

In my luminus project I've added this:
[org.clojure/data.zip "0.1.2"]
to the list of dependencies but this throws an exception still:
(ns myapp.rss
(:use [clojure.data.xml :as xml :only [emit]]))
which is:
Could not locate clojure/data/xml__init.class or clojure/data/xml.clj on classpath
here is a working example to compare with:
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"}
:main hello.core
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/data.xml "0.0.8"]
[org.clojure/data.zip "0.1.2"]
[clj-http "2.2.0"]])
from core.clj:
(ns hello.core
(:require [clj-http.client :as http-client]
[clojure.zip :as zip]
[clojure.xml :as xml]
[clojure.data.xml :as xml-data :refer [emit]]
[clojure.data.zip.xml :as xml-z]))
(use ... :only) has been deprecated by the require :refer pattern.
And here are some common things to check:
you have actually fetched the dependencies since adding them to the project.clj file
Try running lein deps from the command line to make sure fetching the dependencies worked
restart cider (if in emacs)
try from lein repl
if none of this works look in ~/.m2/repository and make sure the class files are there
run ps -ef (if in linux) to look at the command used to start java and make sure the classpath contains your dependency.

Can't run uberjar with Leiningen 2.5.2

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

How do I fix this dependency issue in Clojure?

I'm having a lot of trouble fixing an issue where the dependencies for two different packages are colliding. My project.clj's dependencies look like this:
:dependencies [[org.clojure/clojure "1.6.0"]
[itsy "0.1.1"]
[amazonica "0.3.22" :exclusions [commons-logging org.apache.httpcomponents/httpclient com.fasterxml.jackson.core/jackson-core]]])
My namespace looks like this:
(ns crawler.core
(:require [itsy.core :refer :all])
(:require [itsy.extract :refer :all])
(:use [amazonica.core]
[amazonica.aws.s3]))
When I try to load the namespace into lein's repl with (load crawler/core), I get this error:
CompilerException java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z, compiling:(amazonica/core.clj:1:1)
Online sources suggest that this is a dependency mismatch. How do I fix it?
I put the exclusion on itsy rather than amazonica and it worked. Also fixed the NS form in core.clj.
project.clj:
(defproject blabla "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"]
[itsy "0.1.1" :exclusions [com.fasterxml.jackson.core/jackson-core]]
[amazonica "0.3.22" :exclusions [commons-logging org.apache.httpcomponents/httpclient]]])
core.clj:
(ns blabla.core
(:require [itsy.core :refer :all]
[itsy.extract :refer :all]
[amazonica.core :refer :all]
[amazonica.aws.s3 :refer :all]))
(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
to deal with these situatuions in general run
lein deps :tree
and add exclusions until only the newest versions remain.

Clojure REPL Import trouble-shooting

Okay. I'm trying to muck about with twitter4j inside a Clojure REPL, provided by Leiningen. I've specified twitter4j as a build dependency:
(defproject testproject "0.1.0-SNAPSHOT"
:description "Tryin stuff"
:repositories {
"twitter4j" "http://twitter4j.org/maven2"
}
:dependencies [[org.clojure/clojure "1.5.1"]
[compojure "1.1.6"]
[org.twitter4j/twitter4j-core "3.0.5"]
[org.twitter4j/twitter4j-stream "3.0.5"]]
:plugins [[lein-ring "0.8.8"]]
:ring {:handler testproject.core/app}
:profiles {:dev
{:dependencies [[javax.servlet/servlet-api "2.5"]
[ring-mock "0.1.5"]]}})
So far, so good. lein deps downloads everything without complaint into the default repo in ~/.m2. Awesome. I fire up the REPL, and I get this and only this:
user=> (import '(org.twitter4j.conf ConfigurationBuilder))
ClassNotFoundException org.twitter4j.conf.ConfigurationBuilder java.net.URLClassLoader$1.run (URLClassLoader.java:202)
The twitter4j jars are all present and accounted for, in ~/.m2/org/twitter4j/twitter4j-core/3.0.5/. Is there... something I don't get about importing Java classes? Some extra config I need to provide?
Try this (the proper package name):
user=> (import '(twitter4j.conf ConfigurationBuilder))