2012-12-28 48 views
0

我正在嘗試關注這個tutuorial https://devcenter.heroku.com/articles/clojure-web-application。儘管我在設置本地postgresql數據庫進行測試時遇到了一些困難。使用clojure與Windows一起設置本地PostgreSQL實例?

第一個障礙是在windows shell中運行「postgres -D pg」導致「不允許使用具有管理權限的用戶執行PostgreSQL」的錯誤。爲了得到一個回合,我試着運行pg_ctl start -D。\我想它是有效的,除了它不能訪問「postgresql.conf」文件。

運行「creatdb shouter」也沒有工作,所以我跑了「createdb -U postgres shouter」。但現在當我嘗試推出雷音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) 
+0

你真的應該考慮在Linux而不是Windows這樣做。 – Falmarri

+0

Windows是好的,至少在我看來應該是Clojure的一流開發環境(我們*應該努力做到這一點),如果你不想在Linux機器上運行PostgreSQL實例並保持在你的舒適的Windows環境,然後使用PuTTY在Linux機箱上添加一個「本地端口forwad」到端口5432可以使這更方便。 –

回答

1

這看起來像你的project.clj文件可在沒有指定正確的依賴關係。這裏是有工作的依賴性與比較簡單的例子項目:

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.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