linux.startup.sh.vtl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javapackager Show documentation
Show all versions of javapackager Show documentation
Hybrid Maven/Gradle plugin to package Java applications as native Windows, Mac OS X or GNU/Linux executables and create installers for them
The newest version!
#set ($vmArgs = $StringUtils.join($info.vmArgs, " "))
#!/usr/bin/env bash
# GNU/Linux startup script generated by JavaPackager plugin
SCRIPTPATH=$(dirname "$(readlink -e "$0")")
#if ($info.bundleJre)
JAVA="$SCRIPTPATH/${info.jreDirectoryName}/bin/java"
#else
function showMessage() {
if type -p notify-send; then
notify-send -u critical "${info.name}" "$1"
else
echo $1
fi
}
if type -p java > /dev/null; then
JAVA=java
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
JAVA="$JAVA_HOME/bin/java"
else
showMessage "Java not installed"
exit 1
fi
#if ($info.jreMinVersion)
function compareVersions() {
[[ "$1" == "$2" ]] && return 0
local IFS=.
local i v1 v2
read -r -a v1 <<< "$1"
read -r -a v2 <<< "$2"
for ((i=${#v1[@]}; i<${#v2[@]}; i++))
do
v1[i]=0
done
for ((i=${#v2[@]}; i<${#v1[@]}; i++))
do
v2[i]=0
done
for ((i=0; i<${#v1[@]}; i++))
do
[[ "${v1[$i]}" > "${v2[$i]}" ]] && return 0
[[ "${v1[$i]}" < "${v2[$i]}" ]] && return 1
done
return 0
}
JAVA_VERSION=$("$JAVA" -version 2>&1 | awk -F '"' '/version/ {print $2}')
compareVersions "$JAVA_VERSION" "${info.jreMinVersion}"
if [[ $? != 0 ]]; then
showMessage "The application requires a Java Runtime Environment ${info.jreMinVersion} or higher."
exit 1
fi
#end
#end
#if ($info.linuxConfig.wrapJar)
BINARY="$SCRIPTPATH/${info.executable.name}"
#else
BINARY="$SCRIPTPATH/${info.jarFile.name}"
#end
#if ($info.envPath)
export PATH=${info.envPath}
#end
JVMDefaultOptions="${vmArgs}"
JVMOptionsFile="$SCRIPTPATH/${info.name}.l4j.ini"
[ -f "${JVMOptionsFile}" ] && while read -r option; do JVMDefaultOptions+=" $option"; done <<< $(sed "/^#.*$/d" "${JVMOptionsFile}")
JVMClassPath="$BINARY"
#foreach ($classpath in $info.classpaths)
JVMClassPath+=":${classpath}"
#end
#if ($info.useResourcesAsWorkingDir)
cd "$SCRIPTPATH"
#end
#if ($info.scripts.bootstrap)
# invoke bootstrap script
Bootstrap="$SCRIPTPATH/scripts/${info.bootstrapFile.name}" && [ -x "$Bootstrap" ] && "$Bootstrap"
#end
#if ($info.administratorRequired)
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY GDKBACKEND=x11 "${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" $@
#else
"${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" $@
#end
exit 0