Added tooling to create a standalone binary, using one neat hack!

This commit is contained in:
Simon Brooke 2026-04-03 14:17:55 +01:00
parent e97ace97c5
commit a0a05786ae
4 changed files with 54 additions and 9 deletions

View file

@ -82,9 +82,32 @@ implement one.
You are of course welcome to fork the project and do whatever you like with it! You are of course welcome to fork the project and do whatever you like with it!
### Building
Build with
lein uberjar
This will build a jar file in `target/uberjar/beowulf-VERSION-standalone.jar`,
where VERSION is the current version number.
On UNIX platforms (includeing Linux), you can build a standalone binary by
invoking a script, `resources/sh/builder.sh`, *after* invoking `lein uberjar`,
so:
lein uberjar
sh resources/sh/builder.sh
This should build a standalone binary in `target/beowulf`.
In order to be able to invoke this binary just like any other program, move it
to somewhere on your path, idealy `${HOME}/bin` or `/usr/local/bin`.
### Invoking ### Invoking
Invoke with If you have not built and installed the standalone binary, you may invoke the
uberjar with
java -jar target/uberjar/beowulf-0.3.1-standalone.jar --help java -jar target/uberjar/beowulf-0.3.1-standalone.jar --help
@ -103,13 +126,6 @@ Command line arguments as follows:
To end a session, type `STOP` at the command prompt. To end a session, type `STOP` at the command prompt.
### Building and Invoking
Build with
lein uberjar
### Reader macros ### Reader macros
Currently `SETQ` and `DEFUN` are implemented as reader macros, sort of. It would Currently `SETQ` and `DEFUN` are implemented as reader macros, sort of. It would

View file

@ -25,7 +25,8 @@
:main beowulf.core :main beowulf.core
:plugins [[lein-cloverage "1.2.2"] :plugins [[lein-cloverage "1.2.2"]
[lein-codox "0.10.8"] [lein-codox "0.10.8"]
[lein-environ "1.1.0"]] [lein-environ "1.1.0"]
[lein-shell "0.5.0"]]
:profiles {:jar {:aot :all} :profiles {:jar {:aot :all}
:uberjar {:aot :all} :uberjar {:aot :all}
:dev {:resource-paths ["resources"]}} :dev {:resource-paths ["resources"]}}
@ -36,6 +37,7 @@
["clean"] ["clean"]
["codox"] ["codox"]
["uberjar"] ["uberjar"]
;; ["shell" "resources/sh/builder.sh" ]
["change" "version" "leiningen.release/bump-version"] ["change" "version" "leiningen.release/bump-version"]
["vcs" "commit"]] ["vcs" "commit"]]
:target-path "target/%s" :target-path "target/%s"

19
resources/sh/builder.sh Normal file
View file

@ -0,0 +1,19 @@
#!/bin/sh
# Create an executable from an arbitrary uberjar file.
# I am grateful to
# https://coderwall.com/p/ssuaxa/how-to-make-a-jar-file-linux-executable
# for this extremely cute trick. This version is intended for
# Leiningen projects, but if you can understand this you can
# easily hack it for the conventions of any build tool you use.
#
# Simon Brooke, simon@journeyman.cc, 20260403
BASEDIR=$(dirname "$0")
PROJECT=beowulf
BINARY=target/${PROJECT}
cat ${BASEDIR}/stub.sh \
target/uberjar/${PROJECT}*-standalone.jar > ${BINARY} \
&& chmod +x ${BINARY}

8
resources/sh/stub.sh Normal file
View file

@ -0,0 +1,8 @@
#!/bin/sh
MYSELF=`which "$0" 2>/dev/null`
[ $? -gt 0 -a -f "$0" ] && MYSELF="./$0"
java=java
if test -n "$JAVA_HOME"; then
java="$JAVA_HOME/bin/java"
fi
exec "$java" $java_args -jar $MYSELF "$@"