开始使用Emacs中的Datomic和Clojure

时间:2012-05-23 18:30:58

标签: clojure leiningen swank swank-clojure datomic

我的project.clj文件看起来像这样

(defproject cljs-template "0.1.0-SNAPSHOT"
  :description "FIXME: write this!"
  :url "http://example.com/FIXME"
  :dependencies [[org.clojure/clojure "1.4.0-beta4"]
                 [noir-cljs "0.3.0"]
                 [fetch "0.1.0-alpha2"]
                 [noir "1.3.0-beta2"]
                 [org.clojure/core.cache "0.5.0"]
                 [com.datomic/datomic "0.1.3142"
                  :exclusions [org.slf4j/slf4j-nop org.slf4j/slf4j-log4j12]]
                 [ch.qos.logback/logback-classic "1.0.1"]]
  :plugins [[lein-swank "1.4.3"]]
  ;:cljsbuild {:builds [{}]}
  :main ^{:skip-aot true} cljs-template.server)

我的/src/cljs_template/server.clj开头如下:

(ns cljs-template.server
  (:require [noir.server :as server]
            [noir.cljs.core :as cljs]
            [cljs-template.tree :as tree])
  (:use [datomic.api :only [db q] :as d]))

然后我启动swank,在其中运行(in-ns'cljs-template.server),将光标移动到(ns)函数调用的末尾,并尝试使用Ctrl-运行(ns)方法x Ctrl-e。当我这样做时,我收到以下错误。

No message.
  [Thrown class java.lang.ExceptionInInitializerError]

Restarts:
 0: [QUIT] Quit to the SLIME top level
 1: [CAUSE1] Invoke debugger on cause  org.apache.lucene.index.IndexWriterConfig [Thrown class java.lang.ClassNotFoundException]

Backtrace:
  0:    (Unknown Source) java.lang.Class.forName0
  1:      Class.java:247 java.lang.Class.forName
  2:        RT.java:2030 clojure.lang.RT.loadClassForName
  3:         RT.java:417 clojure.lang.RT.load
  4:         RT.java:398 clojure.lang.RT.load
  5:       core.clj:5386 clojure.core/load[fn]
  6:       core.clj:5385 clojure.core/load
  7:     RestFn.java:408 clojure.lang.RestFn.invoke
  8:       core.clj:5200 clojure.core/load-one
  9:       core.clj:5237 clojure.core/load-lib
 10:     RestFn.java:142 clojure.lang.RestFn.applyTo
 11:        core.clj:602 clojure.core/apply
 12:       core.clj:5271 clojure.core/load-libs
 13:     RestFn.java:137 clojure.lang.RestFn.applyTo
 14:        core.clj:602 clojure.core/apply
 15:       core.clj:5352 clojure.core/require
 16:     RestFn.java:436 clojure.lang.RestFn.invoke
 17: fulltext_index.clj:4 datomic.fulltext-index/loading
 18:    (Unknown Source) datomic.fulltext_index__init.load
 19:    (Unknown Source) datomic.fulltext_index__init.<clinit>
 20:    (Unknown Source) java.lang.Class.forName0
 21:      Class.java:247 java.lang.Class.forName
 22:        RT.java:2030 clojure.lang.RT.loadClassForName
 23:         RT.java:417 clojure.lang.RT.load
 24:         RT.java:398 clojure.lang.RT.load
 25:       core.clj:5386 clojure.core/load[fn]
 26:       core.clj:5385 clojure.core/load
 27:     RestFn.java:408 clojure.lang.RestFn.invoke
 28:       core.clj:5200 clojure.core/load-one
 29:       core.clj:5237 clojure.core/load-lib
 30:     RestFn.java:142 clojure.lang.RestFn.applyTo
 31:        core.clj:602 clojure.core/apply
 32:       core.clj:5271 clojure.core/load-libs
 33:     RestFn.java:137 clojure.lang.RestFn.applyTo
 34:        core.clj:602 clojure.core/apply
 35:       core.clj:5352 clojure.core/require
 36:     RestFn.java:703 clojure.lang.RestFn.invoke
 37:            db.clj:4 datomic.db/loading
 38:    (Unknown Source) datomic.db__init.load
 39:    (Unknown Source) datomic.db__init.<clinit>
 40:    (Unknown Source) java.lang.Class.forName0
 41:      Class.java:247 java.lang.Class.forName
 42:        RT.java:2030 clojure.lang.RT.loadClassForName
 43:         RT.java:417 clojure.lang.RT.load
 44:         RT.java:398 clojure.lang.RT.load
 45:       core.clj:5386 clojure.core/load[fn]
 46:       core.clj:5385 clojure.core/load
 47:     RestFn.java:408 clojure.lang.RestFn.invoke
 48:       core.clj:5200 clojure.core/load-one
 49:       core.clj:5237 clojure.core/load-lib
 50:     RestFn.java:142 clojure.lang.RestFn.applyTo
 51:        core.clj:602 clojure.core/apply
 52:       core.clj:5271 clojure.core/load-libs
 53:     RestFn.java:137 clojure.lang.RestFn.applyTo
 54:        core.clj:602 clojure.core/apply
 55:       core.clj:5352 clojure.core/require
 56:     RestFn.java:703 clojure.lang.RestFn.invoke
 57:         query.clj:4 datomic.query/loading
 58:    (Unknown Source) datomic.query__init.load
 59:    (Unknown Source) datomic.query__init.<clinit>
 60:    (Unknown Source) java.lang.Class.forName0
 61:      Class.java:247 java.lang.Class.forName
 62:        RT.java:2030 clojure.lang.RT.loadClassForName
 63:         RT.java:417 clojure.lang.RT.load
 64:         RT.java:398 clojure.lang.RT.load
 65:       core.clj:5386 clojure.core/load[fn]
 66:       core.clj:5385 clojure.core/load
 67:     RestFn.java:408 clojure.lang.RestFn.invoke
 68:       core.clj:5200 clojure.core/load-one
 69:       core.clj:5237 clojure.core/load-lib
 70:     RestFn.java:142 clojure.lang.RestFn.applyTo
 71:        core.clj:602 clojure.core/apply
 72:       core.clj:5271 clojure.core/load-libs
 73:     RestFn.java:137 clojure.lang.RestFn.applyTo
 74:        core.clj:602 clojure.core/apply
 75:       core.clj:5352 clojure.core/require
 76:     RestFn.java:421 clojure.lang.RestFn.invoke
 77:           api.clj:6 datomic.api/loading
 78:    (Unknown Source) datomic.api__init.load
 79:    (Unknown Source) datomic.api__init.<clinit>
 80:    (Unknown Source) java.lang.Class.forName0
 81:      Class.java:247 java.lang.Class.forName
 82:        RT.java:2030 clojure.lang.RT.loadClassForName
 83:         RT.java:417 clojure.lang.RT.load
 84:         RT.java:398 clojure.lang.RT.load
 85:       core.clj:5386 clojure.core/load[fn]
 86:       core.clj:5385 clojure.core/load
 87:     RestFn.java:408 clojure.lang.RestFn.invoke
 88:       core.clj:5200 clojure.core/load-one
 89:       core.clj:5237 clojure.core/load-lib
 90:     RestFn.java:142 clojure.lang.RestFn.applyTo
 91:        core.clj:602 clojure.core/apply
 92:       core.clj:5271 clojure.core/load-libs
 93:     RestFn.java:137 clojure.lang.RestFn.applyTo
 94:        core.clj:604 clojure.core/apply
 95:       core.clj:5363 clojure.core/use
 96:     RestFn.java:408 clojure.lang.RestFn.invoke
 97:    NO_SOURCE_FILE:1 cljs-template.server/eval1941[fn]
 98:    NO_SOURCE_FILE:1 cljs-template.server/eval1941
 99:  Compiler.java:6465 clojure.lang.Compiler.eval
 100:  Compiler.java:6455 clojure.lang.Compiler.eval
 101:  Compiler.java:6431 clojure.lang.Compiler.eval
 102:       core.clj:2795 clojure.core/eval
 103:        core.clj:532 swank.core/eval782[fn]
 104:    MultiFn.java:163 clojure.lang.MultiFn.invoke
 105:        basic.clj:54 swank.commands.basic/eval-region
 106:        basic.clj:44 swank.commands.basic/eval-region
 107:        basic.clj:73 swank.commands.basic/eval968[fn]
 108:        Var.java:401 clojure.lang.Var.invoke
 109:    (Unknown Source) user/eval1937
 110:  Compiler.java:6465 clojure.lang.Compiler.eval
 111:  Compiler.java:6431 clojure.lang.Compiler.eval
 112:       core.clj:2795 clojure.core/eval
 113:        core.clj:100 swank.core/eval-in-emacs-package
 114:        core.clj:256 swank.core/eval-for-emacs
 115:        Var.java:409 clojure.lang.Var.invoke
 116:        AFn.java:167 clojure.lang.AFn.applyToHelper
 117:        Var.java:518 clojure.lang.Var.applyTo
 118:        core.clj:600 clojure.core/apply
 119:        core.clj:107 swank.core/eval-from-control
 120:        core.clj:330 swank.core/spawn-worker-thread[fn]
 121:        AFn.java:159 clojure.lang.AFn.applyToHelper
 122:        AFn.java:151 clojure.lang.AFn.applyTo
 123:        core.clj:600 clojure.core/apply
 124:        core.clj:326 swank.core/spawn-worker-thread[fn]
 125:     RestFn.java:397 clojure.lang.RestFn.invoke
 126:         AFn.java:24 clojure.lang.AFn.run
 127:     Thread.java:662 java.lang.Thread.run

然后按0关闭堆栈跟踪,再次按(Ctrl)调用Ctrl-x Ctrl-e,现在我的错误是:

Could not initialize class datomic.api__init
  [Thrown class java.lang.NoClassDefFoundError]

Restarts:
 0: [QUIT] Quit to the SLIME top level

Backtrace:
  0:    (Unknown Source) java.lang.Class.forName0
  1:      Class.java:247 java.lang.Class.forName
  2:        RT.java:2030 clojure.lang.RT.loadClassForName
  3:         RT.java:417 clojure.lang.RT.load
  4:         RT.java:398 clojure.lang.RT.load
  5:       core.clj:5386 clojure.core/load[fn]
  6:       core.clj:5385 clojure.core/load
  7:     RestFn.java:408 clojure.lang.RestFn.invoke
  8:       core.clj:5200 clojure.core/load-one
  9:       core.clj:5237 clojure.core/load-lib
 10:     RestFn.java:142 clojure.lang.RestFn.applyTo
 11:        core.clj:602 clojure.core/apply
 12:       core.clj:5271 clojure.core/load-libs
 13:     RestFn.java:137 clojure.lang.RestFn.applyTo
 14:        core.clj:604 clojure.core/apply
 15:       core.clj:5363 clojure.core/use
 16:     RestFn.java:408 clojure.lang.RestFn.invoke
 17:    NO_SOURCE_FILE:1 cljs-template.server/eval6292[fn]
 18:    NO_SOURCE_FILE:1 cljs-template.server/eval6292
 19:  Compiler.java:6465 clojure.lang.Compiler.eval
 20:  Compiler.java:6455 clojure.lang.Compiler.eval
 21:  Compiler.java:6431 clojure.lang.Compiler.eval
 22:       core.clj:2795 clojure.core/eval
 23:        core.clj:532 swank.core/eval782[fn]
 24:    MultiFn.java:163 clojure.lang.MultiFn.invoke
 25:        basic.clj:54 swank.commands.basic/eval-region
 26:        basic.clj:44 swank.commands.basic/eval-region
 27:        basic.clj:73 swank.commands.basic/eval968[fn]
 28:        Var.java:401 clojure.lang.Var.invoke
 29:    (Unknown Source) cljs-template.server/eval6288
 30:  Compiler.java:6465 clojure.lang.Compiler.eval
 31:  Compiler.java:6431 clojure.lang.Compiler.eval
 32:       core.clj:2795 clojure.core/eval
 33:        core.clj:100 swank.core/eval-in-emacs-package
 34:        core.clj:256 swank.core/eval-for-emacs
 35:        Var.java:409 clojure.lang.Var.invoke
 36:        AFn.java:167 clojure.lang.AFn.applyToHelper
 37:        Var.java:518 clojure.lang.Var.applyTo
 38:        core.clj:600 clojure.core/apply
 39:        core.clj:107 swank.core/eval-from-control
 40:        core.clj:330 swank.core/spawn-worker-thread[fn]
 41:        AFn.java:159 clojure.lang.AFn.applyToHelper
 42:        AFn.java:151 clojure.lang.AFn.applyTo
 43:        core.clj:600 clojure.core/apply
 44:        core.clj:326 swank.core/spawn-worker-thread[fn]
 45:     RestFn.java:397 clojure.lang.RestFn.invoke
 46:         AFn.java:24 clojure.lang.AFn.run
 47:     Thread.java:662 java.lang.Thread.run

我做错了什么?如何使用swank / slime在我的emacs中使用datomic。

2 个答案:

答案 0 :(得分:4)

原来我正在执行错误的命令。

我正在运行lein deps并收到以下错误。

...
Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=com.datomic -DartifactId=datomic -Dversion=0.1.3157 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=com.datomic -DartifactId=datomic -Dversion=0.1.3157 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
    1) org.apache.maven:super-pom:pom:2.0
    2) com.datomic:datomic:jar:0.1.3157

我看到下载的数据组代码中的README文件也包含了向我的mvn添加datomic的提及。当然(这是愚蠢的部分)我认为他们说的是同样的事情。

莱恩会告诉你应该执行

mvn install:install-file -DgroupId=com.datomic -DartifactId=datomic -Dversion=0.1.3157 -Dpackaging=jar -Dfile=/path/to/file

README说你应该执行

mvn install:install-file -DgroupId=com.datomic -DartifactId=datomic -Dfile=datomic-${DATOMIC-VERSION}.jar -DpomFile=pom.xml

您是否注意到README指令还包含一个pom.xml文件?我也不!是的,这很重要。

无论如何,请务必同时包含pom.xml文件。如果您尝试将datomic 0.1.3157添加到mvn存储库,则可以在下载的datomic目录中执行以下命令。

mvn install:install-file -DgroupId=com.datomic -DartifactId=datomic -Dfile=datomic-0.1.3157.jar -DpomFile=pom.xml

答案 1 :(得分:3)

我发布了working project here

我调试swank问题的常见疑问是:

  • 是leiningen最新的
  • lein-swank的版本
  • emacs版本(Emacs 24,我发现它更可靠)
  • lib dir中剩余的旧依赖项
编辑:获取数据组jar的正确方法正如Stephen Cagle所说,复制自下面的评论:

 mvn install:install-file -DgroupId=com.datomic -DartifactId=datomic -Dfile=datomic-${DATOMIC-VERSION}.jar