Reputation: 512
Could clojure.java.io/resource load file from classpath but outside of the jar file? When I put file within jar file, it'd load file but when I put file outside jar but in classpath it'd not load file.
Example
Jar name: hello.jar within jar there is file hello.txt
java -jar hello.jar
I saw no problem to read file hello.txt file using line bellow
(->
"hello.txt"
(clojure.java.io/resource)
(clojure.java.io/file)
(slurp))
But when I put hello.txt outside of the jar but in classpath, it fails to load file.
java -cp . -jar hello.jar
hello.txt file in same directory with hello.jar file.
Br, Mamun
Upvotes: 5
Views: 1562
Reputation: 7328
You can't mix -cp
and -jar
cmdline arguments in that way. You can either do...
java -cp ".:hello.jar" com.foo.Class # should use ; instead of : on Windows
or add a
Class-Path: /some/dir/with/hello /some/dir/with/hello/hello.jar
entry to the jar META-INF/MANIFEST.MF
file that includes local directory.(details)
I would recommend you don't use . as the directory, since this will be prone to errors or maybe security issues if the jar file moves.
Upvotes: 3