繁体   English   中英

Clojure:clojure.java.io/resource如何加载文件?

[英]Clojure: How does clojure.java.io/resource load file?

clojure.java.io/resource可以从classpath加载文件但在jar文件之外吗? 当我把文件放在jar文件中时,它会加载文件但是当我把文件放在jar之外但是在classpath中它不会加载文件。

jar名称:jar中的hello.jar有文件hello.txt

java -jar hello.jar 

我看到使用line bellow读取文件hello.txt文件没有问题

(->
  "hello.txt"
  (clojure.java.io/resource)
  (clojure.java.io/file)
  (slurp))

但是当我把hello.txt放在jar之外但是在classpath中时,它无法加载文件。

java -cp . -jar hello.jar 

与hello.jar文件在同一目录中的hello.txt文件。

Br,Mamun

你不能以这种方式混合-cp-jar cmdline参数。 你可以做......

java -cp ".:hello.jar" com.foo.Class  # should use ; instead of : on Windows

或者添加一个

Class-Path: /some/dir/with/hello /some/dir/with/hello/hello.jar

进入包含本地目录的jar META-INF/MANIFEST.MF文件。( 详情

我建议你不要使用。 作为目录,因为如果jar文件移动,这将容易出错或者可能出现安全问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM