environ
environ copied to clipboard
.boot-env file causing errors when starting from uberjar
I haven't been able to get boot-environ working with a simple uberjar. Attached is a minimal example of what happens:
If I run this with
boot bug
java -jar target/project.jar
I get an exception
Caused by: java.lang.IllegalArgumentException: Not a file: jar:file:/home/hinton/temp/environ-bug/target/project.jar!/.boot-env
at clojure.java.io$fn__10864.invokeStatic(io.clj:61)
at clojure.java.io$fn__10864.invoke(io.clj:44)
at clojure.java.io$fn__10838$G__10820__10843.invoke(io.clj:35)
at clojure.java.io$file.invokeStatic(io.clj:424)
at clojure.java.io$file.invoke(io.clj:418)
at environ.core$read_env_file.invokeStatic(core.clj:34)
at environ.core$read_env_file.invoke(core.clj:33)
at environ.core$fn__226.invokeStatic(core.clj:43)
at environ.core$fn__226.invoke(core.clj:39)
at environ.core__init.load(Unknown Source)
at environ.core__init.<clinit>(Unknown Source)
... 42 more
Whereas I expect it to print "spork" and exit.
I have had a quick look at the source - I think this line may not be correct.
If I eval something like (io/file (io/resource "META-INF/MANIFEST.MF"))
in a clojure repl I get the same form of exception. I think that passing (io/resource ".boot-env")
to read-env-file
which then passes it to io/file
cannot work when io/resource
returns a resource from within a jar file. This may have worked in some circumstances where the classpath contains the resource as a file rather than as an entry in a jar.
I think if you use io/reader
instead of io/file
it will work as slurp
should work on reader
and reader
is polymorphic for both input types.
See https://github.com/weavejester/environ/pull/81
It looks like this is caused by .boot-env
being erroneously included in the jar file, which may be why this hasn't been reported before. In any case, Environ is behaving incorrectly.
Oh right, I thought the intention was that .boot-env would be read from the jar file (so you'd ship the defaults baked into the jar but then replace them with env vars or whatever). I will fix my pull request in a sec.