Clojure: How is the clojure.java.io/resource download file?

Can clojure.java.io/resource load a file from pathpath, but outside the jar file? When I put the file in the jar file, it loads the file, but when I put the file outside the jar, but in the classpath it does not load the file.

Example

Jar name: hello.jar Inside the jar there is a hello.txt file

java -jar hello.jar 

I did not see a problem reading the hello.txt file using the line below

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

But when I put hello.txt outside the jar, but in the classpath, it cannot load the file.

java -cp . -jar hello.jar 

hello.txt file in the same directory as the hello.jar file.

Br, Mamun

+4
source share
1 answer

You cannot mix arguments -cpand -jarcmdline in this way. You can do it...

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

or add

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

jar META-INF/MANIFEST.MF, . (details)

. , , jar .

+2

Source: https://habr.com/ru/post/1529444/


All Articles