我在我的应用程序中使用clojure.java.classpath,并且想知道我缺少什么设置,因为当我从uberjar运行时clojure.java.classpath/classpath-directories
的输出为空。
这是一个最小的工作示例:
project.clj:
(defproject cptest "0.1.0-SNAPSHOT"
:description "classpath test"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/java.classpath "0.2.2"]]
:profiles {:uberjar {:aot :all}}
:omit-source true
:main cptest.core)
和src / cptest / core.clj:
(ns cptest.core
(:require [clojure.java.classpath :as cp])
(:gen-class))
(defn -main [& args]
(println "Classpath directories" (cp/classpath-directories)))
运行lein run
时,我会
`Classpath directories (#object[java.io.File 0x14555e0a /home/phil/cptest/src] #object[java.io.File 0x4bb33f74 /home/phil/cptest/target/classes])`
如果使用lein uberjar
创建一个uberjar,那么
`java -jar /home/phil/cptest/target/cptest-0.1.0-SNAPSHOT-standalone.jar`
输出为空。 Classpath directories ()
。
jar tf /home/phil/cptest/target/cptest-0.1.0-SNAPSHOT-standalone.jar | grep cptest
的输出(完整输出非常长):
META-INF/maven/cptest/cptest/pom.xml
META-INF/leiningen/cptest/cptest/project.clj
META-INF/maven/cptest/
META-INF/maven/cptest/cptest/
META-INF/maven/cptest/cptest/pom.properties
cptest/
cptest/core$fn__72.class
cptest/core$_main.class
cptest/core.class
cptest/core__init.class
cptest/core$loading__5340__auto____21.class
cptest/core.clj
UPADTE
检查clojure/java/classpath.clj
,似乎是对
(classpath (clojure.lang.RT/baseLoader))
lein run
与uberjar
方法的行为方式不同,classpath
定义为:
(defn classpath
"Returns a sequence of File objects of the elements on the classpath."
([classloader]
(distinct
(mapcat
loader-classpath
(take-while
identity
(iterate #(.getParent ^ClassLoader %) classloader)))))
([] (classpath (clojure.lang.RT/baseLoader))))