0

project.clj ファイルに次のコードがあります。

(defproject pinger "0.0.1-SNAPSHOT"
  :description "A website availability tester"
  :dependencies [[org.clojure/clojure "1.3.0"]]
  :main pinger.core)

(ns pinger.core
  (:import (java.net URL HttpURLConnection))
  (:gen-class))

(defn response-code [address]
  (let [conn ^HttpURLConnection (.openConnection (URL. address))
    code (.getResponseCode conn)]
    (when (< code 400)
      (-> conn .getInputStream .close))
    code))

(defn available? [address]
  (= 200 (response-code address)))

(defn -main []
  (let [addresses '("http://google.com"
            "http://amazon.com"
            "http://google.com/badurl")]
    (while true
      (doseq [address addresses]
    (println (available? address)))
      (Thread/sleep (* 1000 60)))))

uberjar を作成します。

C:\Documents and Settings\vreinpa\My Documents\Books\ProgrammingClojure\code\src
\pinger>lein uberjar
Cleaning up.
Copying 1 file to C:\Documents and Settings\vreinpa\My Documents\Books\Programmi
ngClojure\code\src\pinger\lib
Warning: *classpath* not declared dynamic and thus is not dynamically rebindable
, but its name suggests otherwise. Please either indicate ^:dynamic *classpath*
or change the name.
Copying 1 file to C:\Documents and Settings\vreinpa\My Documents\Books\Programmi
ngClojure\code\src\pinger\lib
Created C:\Documents and Settings\vreinpa\My Documents\Books\ProgrammingClojure\
code\src\pinger/pinger-0.0.1-SNAPSHOT.jar
Including pinger-0.0.1-SNAPSHOT.jar
Including clojure-1.3.0.jar
Created C:\Documents and Settings\vreinpa\My Documents\Books\ProgrammingClojure\
code\src\pinger/pinger-0.0.1-SNAPSHOT-standalone.jar

次に、その uberjar を実行しようとすると、次のエラーが発生します。

C:\Documents and Settings\vreinpa\My Documents\Books\ProgrammingClojure\code\src
\pinger>java -jar pinger-0.0.1-SNAPSHOT-standalone.jar
Exception in thread "main" java.lang.NoClassDefFoundError: pinger/core
Caused by: java.lang.ClassNotFoundException: pinger.core
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: pinger.core. Program will exit.

ここで何が間違っていますか?

4

2 に答える 2

3

あなたの他の質問に答えて私が言ったように、project.clj ファイルはソース コードを置く場所ではありませ。そして、そこに定義した名前空間のロードを確実に台無しにします。ソース ライブラリの規則に従い、ファイルをプロジェクト ツリーの src ディレクトリに配置します。

于 2012-01-26T17:14:42.553 に答える