Skip to content

Instantly share code, notes, and snippets.

@clintval
Created April 3, 2024 21:47
Show Gist options
  • Select an option

  • Save clintval/bc760c2227b373a1957a23d2e551984d to your computer and use it in GitHub Desktop.

Select an option

Save clintval/bc760c2227b373a1957a23d2e551984d to your computer and use it in GitHub Desktop.

Revisions

  1. clintval created this gist Apr 3, 2024.
    28 changes: 28 additions & 0 deletions make-jar-executable.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    {
    cat <<- EOM
    #!/usr/bin/env sh
    set -e
    PROP_OPTS=()
    MEM_OPTS=()
    PASS_ARGS=()
    DEFAULT_MEM_OPTS=('-Xms512m' '-XX:+AggressiveHeap')
    for ARG in "\$@"; do
    case \$ARG in
    '-D'* | '-XX'*) PROP_OPTS+=("\$ARG");;
    '-Xm'*) MEM_OPTS+=("\$ARG");;
    *) PASS_ARGS+=("\$ARG");;
    esac
    done
    if [ -z "\${_JAVA_OPTIONS}" ] && [ -z "\${JAVA_OPTS}" ] && [ -z "\${MEM_OPTS}" ]; then
    MEM_OPTS=("\${DEFAULT_MEM_OPTS[*]}");
    fi
    exec java \${JAVA_OPTS} \${MEM_OPTS[*]} \${PROP_OPTS[*]} -jar "\$0" \${PASS_ARGS[*]}
    exit
    EOM
    cat /path/to/your/custom/build/project.jar
    } > project && chmod 775 project