我在文件 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.
我在这里做错了什么?