Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.boot-env file causing errors when starting from uberjar #80

Open
larkery opened this issue Apr 17, 2018 · 4 comments
Open

.boot-env file causing errors when starting from uberjar #80

larkery opened this issue Apr 17, 2018 · 4 comments

Comments

@larkery
Copy link

larkery commented Apr 17, 2018

I haven't been able to get boot-environ working with a simple uberjar. Attached is a minimal example of what happens:

environ-bug.zip

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.

@larkery
Copy link
Author

larkery commented Apr 17, 2018

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.

@larkery
Copy link
Author

larkery commented Apr 17, 2018

See #81

@weavejester
Copy link
Owner

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.

@larkery
Copy link
Author

larkery commented Apr 20, 2018

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.

larkery added a commit to larkery/environ that referenced this issue Apr 20, 2018
Previously, classpath resources were assumed to be files and passed to
io/file. This failed when the resource was within a jar. The fix is to
use io/reader instead, which works on resources within or without
jars.

Fixes: weavejester#80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants