-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeitso.sh
executable file
·74 lines (65 loc) · 2.46 KB
/
makeitso.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
71
72
73
#!/bin/bash
# application packaging example, no copyright claimed, license: https://www.apache.org/licenses/LICENSE-2.0
# this example packages a Java application with an JRE as native application bundle on macOS or Linux
BUILDDIR="tmpbuild"
ICONDIR="app.iconset"
# JDK 17 is minimum for jpackage, older versions or JRE won't work
# they keyworkd "newest" doesn't really exist, any non-matching version number will return the newest installed
if [ $(uname -s) == "Darwin" ]; then
MACOS=1
APPNAME=AppExample
echo "Creating $APPNAME.app macOS application bundle..."
else
unset MACOS
APPNAME=appexample
echo "Creating Linux application bundle $APPNAME..."
fi
if jpackage --version 2>/dev/null | grep -E '^(17|18|19|2)' >/dev/null; then
echo JDK version found: $(jpackage --version)
elif [ "$MACOS" ] && /usr/libexec/java_home -v newest --exec jpackage --version 2>/dev/null | grep -E '^(17|18|19|2)' >/dev/null; then
FOUNDJDK=$(/usr/libexec/java_home -v newest)
PATH="$FOUNDJDK/bin:$PATH"
echo JDK found via /usr/libexec/java_home: $FOUNDJDK
else
echo "Canceled. No JDK 17 or newer found."
exit 1
fi
if [ $MACOS ]; then
# re-using the image file also for the app icon
mkdir -p "$ICONDIR"
rprev=""
for r in 1024 512 256 128 64 32 16; do
sips -z $r $r marsduke.png --out "$ICONDIR/icon_${r}x${r}.png"
if [ "$rprev" ]; then
cp "$ICONDIR/icon_${rprev}x${rprev}.png" "$ICONDIR/icon_${r}x${r}@2x.png"
fi
rprev=$r
done
rm "$ICONDIR/icon_1024x1024.png"
iconutil -c icns "$ICONDIR"
fi
mkdir -p "$BUILDDIR"
cp marsduke.png "$BUILDDIR/"
javac AppExample.java
jar -cvfe "$BUILDDIR/app.jar" AppExample AppExample*.class
# create application bundle with embedded JRE
if [ $MACOS ]; then
# alternatively, use --type dmg instead of --type app-image to create .app bundle inside a .dmg image
jpackage --type app-image \
--dest . --input "$BUILDDIR" --icon app.icns --name $APPNAME \
--main-class AppExample --main-jar app.jar --verbose
rm app.icns
rm -rf "$ICONDIR"
echo "$APPNAME bundle created."
echo "To start it in Terminal.app: $APPNAME.app/Contents/MacOS/$APPNAME"
echo "Or start it from the desktop with a double click on $APPNAME."
else
# Linux
# alternatively, use --type rpm or deb instead of --type app-image
jpackage --type app-image \
--dest . --input "$BUILDDIR" --name $APPNAME \
--main-class AppExample --main-jar app.jar --verbose
echo "$APPNAME bundle created. To start it: $APPNAME/bin/$APPNAME"
fi
rm -rf "$BUILDDIR"
rm AppExample*.class