我正在尝试测试mire。
当我执行此代码时
(ns mire
(:use [clojure.contrib server-socket duck-streams]))
我有java.io.FileNotFoundException
错误。
谷歌搜索发现clojure.contrib
已被弃用,我在project.clj
中添加了服务器套接字作为依赖项,并执行leon repl
以安装jar库
mire> lein repl
Retrieving server-socket/server-socket/1.0.0/server-socket-1.0.0.pom from clojars
Retrieving server-socket/server-socket/1.0.0/server-socket-1.0.0.jar from clojar
然后在emacs / cider中,我尝试使用此代码来获取相同的FileNotFoundException错误。
(ns mire
(:use [server.socket server-socket duck-streams]))
java.io.FileNotFoundException: Could not locate server/socket/server_socket__init.class or
server/socket/server_socket.clj on class path:
在命令行REPL中,(use [server.socket server-socket])
给出了相同的错误消息。
可能有什么问题?我使用emacs / cider / nREPL。这是project.clj。
(defproject mire "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.5.1"]
[server-socket "1.0.0"]])
这是导致错误的代码:
(ns mire
(:use [clojure.contrib server-socket duck-streams]))
(def port (* 3 1111))
(defn mire-handle-client [in out]
(binding [*in* (reader in)
*out* (writer out)]
(loop []
(println (read-line))
(recur))))
(def server (create-server port mire-handle-client))
答案 0 :(得分:1)
从Building an Echo Server in Clojure - Part 2中的代码中,这是server.socket
的工作代码。
(ns mire
(:use server.socket))
(import '[java.io BufferedReader InputStreamReader OutputStreamWriter])
(def port (* 3 1111))
(defn mire-handle-client [in out]
(binding [*in* (BufferedReader. (InputStreamReader. in))
*out* (OutputStreamWriter. out)]
(loop []
(println (read-line))
(recur))))
(def server (create-server port mire-handle-client))
答案 1 :(得分:1)
名称空间通常以点分隔。此库中的server.socket
是。
试试这个:
(ns mire (:use [server.socket]))