0

我正在尝试遵循此教程https://devcenter.heroku.com/articles/clojure-web-application。不过,在设置本地 postgresql 数据库进行测试的最初步骤中,我遇到了一些困难。

第一个问题是在 windows shell 中运行“postgres -D pg”会导致“不允许具有管理权限的用户执行 PostgreSQL”的错误。为了得到一个回合,我尝试运行 pg_ctl start -D .\ 。我认为它有效,除了它无法访问“postgresql.conf”文件。

运行“creatdb 呼喊者”也不起作用,所以我运行了“createdb -U postgres 呼喊者”。但是现在当我尝试启动 lein repl 时,我得到了这个错误:

$lein repl
Could not find artifact postgresql:postgresql:pom:8.4-702.qdbc4 in central (http://repo1.maven.org/maven2
Could not find artifact postgresql:postgresql:pom:8.4-702.qdbc4 in clojars (https://clojars.org/repo/)
Could not find artifact postgresql:postgresql:jar:8.4-702.qdbc4 in central (http://repo1.maven.org/maven2
Could not find artifact postgresql:postgresql:jar:8.4-702.qdbc4 in clojars (https://clojars.org/repo/)
Check :dependencies and :repositories for typos.
It's possible the specified jar is not in any repository.
If so, see "Free-floating Jars" under http://j.mp/repeatability
Exception in thread "Thread-1" clojure.lang.ExceptionInfo: Could not resolve dependencies {:exit-code 1}
        at clojure.core$ex_info.invoke(core.clj:4227)
        at leiningen.core.classpath$get_dependencies.doInvoke(classpath.clj:128)
        at clojure.lang.RestFn.invoke(RestFn.java:425)
        at clojure.lang.AFn.applyToHelper(AFn.java:163)
        at clojure.lang.RestFn.applyTo(RestFn.java:132)
        at clojure.core$apply.invoke(core.clj:605)
        at leiningen.core.classpath$resolve_dependencies.doInvoke(classpath.clj:144)
        at clojure.lang.RestFn.invoke(RestFn.java:425)
        at leiningen.core.eval$prep.invoke(eval.clj:60)
        at leiningen.core.eval$eval_in_project.invoke(eval.clj:220)
        at leiningen.repl$start_server.doInvoke(repl.clj:65)
        at clojure.lang.RestFn.invoke(RestFn.java:470)
        at leiningen.repl$repl$fn__1788.invoke(repl.clj:145)
        at clojure.lang.AFn.applyToHelper(AFn.java:159)
        at clojure.lang.AFn.applyTo(AFn.java:151)
        at clojure.core$apply.invoke(core.clj:601)
        at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1771)
        at clojure.lang.RestFn.invoke(RestFn.java:425)
        at clojure.lang.AFn.applyToHelper(AFn.java:163)
        at clojure.lang.RestFn.applyTo(RestFn.java:132)
        at clojure.core$apply.invoke(core.clj:605)
        at clojure.core$bound_fn_STAR_$fn__3984.doInvoke(core.clj:1793)
        at clojure.lang.RestFn.invoke(RestFn.java:397)
        at clojure.lang.AFn.run(AFn.java:24)
        at java.lang.Thread.run(Unknown Source)
4

1 回答 1

1

看起来您的 project.clj 文件可能没有指定正确的依赖项。这是一个简短的示例项目,它具有工作依赖项,可以与之进行比较:

项目.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.4.0"]
                 [org.clojure/java.jdbc "0.2.3"]
                 [postgresql/postgresql "8.4-702.jdbc4"]])

这适用于repl。

user> (require '[clojure.java.jdbc :as sql])
nil

user> (def pgsqldb {:subprotocol "postgresql"                                                              
                    :subname "//127.0.0.1:5432/dbname"                                                    
                    :user "postgres"                                                                       
                    :password "...."})
#'user/pgsqldb
user> (sql/with-connection pgsqldb )
nil

user> (sql/with-connection pgsqldb 
         (sql/with-query-results rs ["SELECT * 
                                      FROM information_schema.tables 
                                      WHERE table_type = 'BASE TABLE' 
                                        AND table_schema = 'public' 
                                      ORDER BY table_type, table_name"] 
           (count rs)))
50
于 2012-12-29T03:36:44.687 回答