java.lang.IllegalArgumentException:没有方法的实现:: protocol-matches of protocol:#'clout.core / Route

时间:2015-06-30 04:17:03

标签: clojure compojure

我有两个感兴趣的文件: 的 build.boot

(set-env!
 :source-paths #{"src/clj" "src/cljs" "test/clj"}
 :resource-paths #{"html" "target/main.js"}
 :dependencies '[[adzerk/boot-cljs      "0.0-3308-0"]
                 [adzerk/boot-cljs-repl "0.1.10-SNAPSHOT"]
                 [adzerk/boot-reload    "0.3.1"]
                 [adzerk/boot-test "1.0.4"]
                 [cljsjs/hammer "2.0.4-4"]
                 [compojure "1.3.1"]
                 [com.datomic/datomic-pro "0.9.5186"]
                 [hiccup "1.0.5"]
                 [org.clojure/clojure "1.7.0-RC1"]
                 [org.clojure/clojurescript "0.0-3308"]
                 [org.clojure/core.async "0.1.346.0-17112a-alpha"]
                 [org.clojure/test.check "0.7.0"]
                 [org.omcljs/om "0.8.8"]
                 [pandeiro/boot-http "0.6.3-SNAPSHOT"]
                 [ring/ring-devel "1.4.0-RC1"]
                 [http-kit "2.1.18"]])

(require
 '[adzerk.boot-cljs      :refer [cljs]]
 '[adzerk.boot-cljs-repl :refer [cljs-repl start-repl]]
 '[adzerk.boot-reload    :refer [reload]]
 '[adzerk.boot-test      :refer [test]]
 '[pandeiro.boot-http    :refer [serve]])

(task-options!
 cljs {:source-map true
       :optimizations :none
       :pretty-print true})

(deftask build
  "Build an uberjar of this project that can be run with java -jar"
  []
  (comp
   (cljs)
   (aot :namespace '#{vidiot.server})
   (pom :project 'vidiot
        :version "0.1.0")
   (uber)
   (jar :main 'vidiot.server)))

src / clj / vidiot / server.clj

(ns vidiot.server
  (:gen-class)
  (:require
   [compojure.core :refer :all]
   [compojure.route :as route]
   [hiccup.core :refer :all]
   [org.httpkit.server :refer :all]
   [ring.middleware.reload :as reload]
   [ring.util.response :as response]))

(defonce server (atom nil))

(defroutes all-routes

  (GET "/" [] (response/redirect "index.html"))

  (GET "/ws" [request]
       (with-channel request channel
         (on-close
          channel
          (fn [status]
            (println "channel closed: " status)))

         (on-receive
          channel
          (fn [data] ;; echo it back
            (send! channel data)))))

  (route/files "/" {:root "target"})

  (route/not-found (response/response (html [:div#erro "Page Not Found"]))))

(defn -main [& args]
  (run-server all-routes {:port 8080}))

然后我,

 > boot build
 > java -jar target/vidiot-0.1.0.jar

然后在我的浏览器中转到localhost:9090,终端打印。

java.lang.IllegalArgumentException: No implementation of method: :route-matches of protocol: #'clout.core/Route found for class: clout.core.CompiledRoute
    at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:554)
    at clout.core$eval5590$fn__5591$G__5581__5598.invoke(core.clj:39)
    at compojure.core$if_route$fn__5887.invoke(core.clj:40)
    at compojure.core$if_method$fn__5879.invoke(core.clj:27)
    at compojure.core$routing$fn__5918.invoke(core.clj:127)
    at clojure.core$some.invoke(core.clj:2568)
    at compojure.core$routing.doInvoke(core.clj:127)
    at clojure.lang.RestFn.applyTo(RestFn.java:139)
    at clojure.core$apply.invoke(core.clj:630)
    at compojure.core$routes$fn__5922.invoke(core.clj:132)
    at org.httpkit.server.HttpHandler.run(RingHandler.java:91)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

我可以通过将 build.boot 中的:dependencies 降级为[compojure "1.1.6"]来解决此问题。

所以,我的问题是,为什么我在构建我的uberjar时不能使用[compojure "1.3.4"](撰写本文时的最新版本)?

2 个答案:

答案 0 :(得分:3)

aot修复问题后放置uber任务。

(task-options! pom {:project 'my-project
                    :version "0.1.0"}
               jar {:main 'my-project.core}
               aot {:namespace '#{my-project.core}})

(deftask build []
  (comp (pom)
        (uber)
        (aot)
        (jar)))

答案 1 :(得分:1)

我能够通过为clout文件夹添加排除来解决此问题。看起来uberjar正在解压缩一些已编译的clout文件,这些文件位于从项目源编译的文件之上。我的项目示例:

     (comp (cljs :compiler-options {:output-to "js/main.js"})
           (aot :namespace '#{zoondka-maps.server zoondka-maps.handler})
           (pom :project (symbol (:name project))
                :version (:version project))
           (uber :exclude (conj pod/standard-jar-exclusions #".*\.html" #"clout/.*"))
           (jar :file (str (:name project) ".jar")
                :main 'zoondka-maps.server)))