Skip to content

Instantly share code, notes, and snippets.

@averycowan
Last active June 13, 2023 18:38
Show Gist options
  • Save averycowan/60b050117165d7507931b4d00dfdeeab to your computer and use it in GitHub Desktop.
Save averycowan/60b050117165d7507931b4d00dfdeeab to your computer and use it in GitHub Desktop.
make_jar_executable
#!/usr/bin/env bash
# Usage: make_jar_executable <jarfile>
# This script will make a unix executable copy of any jar file
# A new file will be created with the same path as <jarfile> without the extension
# That file will be executable and is fully self-contained.
# Get the file path
jarfile=$1
# Get the path with no extension
outpath=${jarfile%.*}
# Create the launcher
echo '#!/bin/sh' >> $outpath
echo >> $outpath
echo 'exec java -jar "$0" "$@"' >> $outpath
# Copy the contents of the jar over
cat $jarfile >> $outpath
# Make it executable
chmod +x $outpath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment