-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathjarify.sh
executable file
·46 lines (36 loc) · 1016 Bytes
/
jarify.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
#! /bin/sh
# convert a flat directory into a jar file
# - when run without arguments, convert the current directory
# - when run with argument, convert every mentioned directory
for cmd in jar javac; do
if ! command -v $cmd >/dev/null 2>&1; then
echo "Who am I? Why am I here? Am I on lilo? $cmd is missing!" >& 2
exit 1
fi
done
TMPDIR=/tmp/JARIFY
jarify() (
WD="${1:+$1/}"
# check the directory contains java files, if not, quit
for file in "$WD"*java; do
if [ "$file" = "$WD*java" ]; then
exit
fi
break
done
mkdir -p "$TMPDIR"
javac -d "$TMPDIR" -Xlint -Xlint:-unchecked "$WD"*.java
MAINJAVA=$(egrep -l '((public|static)[[:space:]]+){2}void[[:space:]]+main' "$WD"*.java)
MAINJAVA="${MAINJAVA##*/}"
MAINCLASS=$(find "$TMPDIR" -name "${MAINJAVA%.java}.*" -printf "%P\n")
CWD="$PWD"
cd "$TMPDIR"
jar cfe runme.jar "${MAINCLASS%.class}" *
chmod +x runme.jar
cd "$CWD"
cp -f "$TMPDIR/runme.jar" "${WD:-.}"
rm -rf "$TMPDIR"
)
while jarify "$1"; [ "$2" ]; do
shift
done