leiningen

N.B. The maintainers are on #leiningen on Libera chat IRC. Go there for direct support/bug reports.
tees 2020-03-24T20:00:10.051300Z

I'm trying to include a binary executable in my uberjar so that I can shell out to it from within the uberjar. When running jar tvf, I can see that the binary is in the jar... but I can't get to the path of the binary when running the program. Anybody have any tips? I've only found stack over flow suggestions for reading in text files

tees 2020-03-24T20:01:04.052400Z

(def PARSER-PATH (str
                  (.getPath (<http://clojure.java.io/resource|clojure.java.io/resource> "parser"))
                  "/bin/parser"))
This works when running a repl in cider, but my println returns this when running the uberjar with java:
"PARSER PATH IS ----------------- " "file:/Users/tees/Projects/firn/firn/target/uberjar/firn-0.1.0-SNAPSHOT-standalone.jar!/parser/bin/parser"

2020-03-24T20:07:49.053100Z

@tees classpath resources can be loaded by the java process, but not by the OS

2020-03-24T20:07:52.053300Z

at least not directly

2020-03-24T20:08:14.053800Z

you need to write out the parser from the resource onto a filesystem before the OS will execute it

2020-03-24T20:08:50.054800Z

@tees something like (io/copy (io/resource "parser/bin/parser") (io/file "/tmp/bin/parser"))

tees 2020-03-24T20:09:05.055300Z

ahhh.

tees 2020-03-24T20:11:39.055800Z

Thanks @noisesmith. Trying now.

2020-03-24T20:12:00.056200Z

oh you'll need to flip the exec bit too (dunno if there's a way to do that with io/file...)

2020-03-24T20:13:13.056800Z

(.setExecutable f true)

👍 1
tees 2020-03-24T20:16:24.057200Z

Great, will give that a shot.

2020-03-24T20:18:50.057700Z

nb don't use spit as that will try to do text-encoding stuff that will break the executable

tees 2020-03-24T20:20:20.058100Z

Hmm, running into

1. Unhandled java.lang.IllegalArgumentException
   No method in multimethod 'do-copy' for dispatch value: [<http://java.net|java.net>.URL
   <http://java.io|java.io>.File]

tees 2020-03-24T20:20:25.058300Z

when running the io/copy.

2020-03-24T20:20:50.058800Z

try (io/input-stream (io/resource "parser/bin/parser"))

2020-03-24T20:21:02.059100Z

I should have tested that

2020-03-24T20:22:07.059400Z

(ins)user=&gt; (io/copy (io/input-stream (io/resource "clojure/core.clj")) (io/file "core.clj"))
nil
(ins)user=&gt; (count (slurp "core.clj"))
263653

2020-03-24T20:22:32.059700Z

user=&gt; (subs (slurp "core.clj") 0 100)
";   Copyright (c) Rich Hickey. All rights reserved.\n;   The use and distribution terms for this soft"

tees 2020-03-24T20:23:27.060Z

Works! Amazing. Thanks @noisesmith.