-
Notifications
You must be signed in to change notification settings - Fork 1
/
launcher.sh
executable file
·71 lines (62 loc) · 1.48 KB
/
launcher.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
#Set launcher configuration
###########################
version=7
mainclass="cl.rvillablanca.Main"
classpath=""
javaoptions=("-Xms256m" "-Xmx512m")
programname="Launcher Example"
isjar=1
jarfile="jar/launcher.jar"
###########################
check_version() {
out=$("$1" -version 2>&1) || return 0
out=$(echo $out | awk -F '"' 'NR==1{print $2}')
out=${out:2:1}
if [ "$out" -ge "$version" ]; then
return 1
else
return 0
fi
}
run_program() {
local command=$1
args=("$@")
args="${args[@]:1}"
for opt in "${javaoptions[@]}"
do
command="$command ${javaoptions[$i]}"
done
if [ "$isjar" -eq 1 ]; then
command="$command -jar $jarfile"
else
if [ -n "$classpath" ]; then
command="$command -cp $classpath"
fi
command="$command $mainclass"
fi
command="$command $args"
exec $command
}
msg_not_found() {
echo "Cannot find java, be sure to install it (\"$programname\" require java version 1.$version+)"
}
command=java
check_version $command
if [ "$?" -eq 1 ]; then
run_program $command "$@"
else
if [ -n "$JAVA_HOME" ]; then
command="$JAVA_HOME/jre/bin/java"
command2="$JAVA_HOME/bin/java"
if [ -e "$command" ]; then
run_program $command "$@"
elif [ -e "$command2" ]; then
run_program $command2 "$@"
else
msg_not_found
fi
else
msg_not_found
fi
fi