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

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 "$@"