diff options
| author | Kostya <mail@sartin.in> | 2026-10-13 19:19:40 +0300 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-10-13 19:20:05 +0300 |
| commit | da4f3ceb1fc1f317a3cca788b6c9b78ffab12de2 (patch) | |
| tree | e8c70414409640309461c1b7fabbd084c892eb03 | |
| parent | 4edb27d378e8b79931ef6a6abebfda66f894d538 (diff) | |
| download | guess-market-da4f3ceb1fc1f317a3cca788b6c9b78ffab12de2.tar.gz guess-market-da4f3ceb1fc1f317a3cca788b6c9b78ffab12de2.tar.xz guess-market-da4f3ceb1fc1f317a3cca788b6c9b78ffab12de2.zip | |
tools: package the server as a WAR and the client as a directory
The Ex3 submission is exactly one WAR for Tomcat's webapps/ plus a
directory holding the client, its jars and its batch file.
package.sh now stages both under build/dist/ex3. The WAR is named
guess-market.war after the context path the client expects, and carries
the api and service jars with gson and JAXB; Tomcat only has to provide
the servlet API. The client directory holds ui-client, api, ui-fx,
gson, OkHttp and JavaFX, and nothing of the engine.
An executable's Class-Path used to name every module. List only the
modules it depends on, so the client jar no longer points at
service.jar, and stop producing a plain jar for the server module.
Add tomcat.sh to try the result by hand: it copies the packaged WAR
into a local Tomcat ($CATALINA_HOME, or the newest
C:\tomcat\apache-tomcat-*) and runs it in the foreground.
| -rw-r--r-- | tools/_util.sh | 8 | ||||
| -rw-r--r-- | tools/package.sh | 37 | ||||
| -rw-r--r-- | tools/tomcat.sh | 38 |
3 files changed, 81 insertions, 2 deletions
diff --git a/tools/_util.sh b/tools/_util.sh index 65cba8c..8323c61 100644 --- a/tools/_util.sh +++ b/tools/_util.sh | |||
| @@ -22,6 +22,14 @@ MAINCLASS_ui_console="market.guess.ui.console.App" | |||
| 22 | MAINCLASS_ui_desktop="market.guess.ui.desktop.Launcher" | 22 | MAINCLASS_ui_desktop="market.guess.ui.desktop.Launcher" |
| 23 | MAINCLASS_ui_client="market.guess.ui.client.Launcher" | 23 | MAINCLASS_ui_client="market.guess.ui.client.Launcher" |
| 24 | 24 | ||
| 25 | # Exercise 3 submission: one WAR for Tomcat's webapps/ and a self-contained client directory. | ||
| 26 | # The WAR is named after the context path the client expects (/guess-market). | ||
| 27 | WAR_MODULE="server" | ||
| 28 | WAR_NAME="guess-market" | ||
| 29 | WAR_LIB_DIRS="gson jaxb" | ||
| 30 | CLIENT="ui-client" | ||
| 31 | CLIENT_LIB_DIRS="gson openjfx okhttp" | ||
| 32 | |||
| 25 | JAVA_HOME_DIR=$(java -XshowSettings:properties -version 2>&1 | tr -d '\r' | sed -n 's/^ *java\.home = //p') | 33 | JAVA_HOME_DIR=$(java -XshowSettings:properties -version 2>&1 | tr -d '\r' | sed -n 's/^ *java\.home = //p') |
| 26 | case "$(uname -s)" in | 34 | case "$(uname -s)" in |
| 27 | CYGWIN*|MINGW*|MSYS*) | 35 | CYGWIN*|MINGW*|MSYS*) |
diff --git a/tools/package.sh b/tools/package.sh index ce18f63..2569e96 100644 --- a/tools/package.sh +++ b/tools/package.sh | |||
| @@ -33,8 +33,7 @@ echo "=== Generating executable manifests ===" | |||
| 33 | # this line is the entire classpath at runtime. | 33 | # this line is the entire classpath at runtime. |
| 34 | for e in $EXECUTABLES; do | 34 | for e in $EXECUTABLES; do |
| 35 | CPLINE="" | 35 | CPLINE="" |
| 36 | for m in $MODULES; do | 36 | for m in $(deps_of "$e"); do |
| 37 | [ "$m" = "$e" ] && continue | ||
| 38 | CPLINE="$CPLINE${CPLINE:+ }$m.jar" | 37 | CPLINE="$CPLINE${CPLINE:+ }$m.jar" |
| 39 | done | 38 | done |
| 40 | for d in $RUNTIME_LIB_DIRS; do | 39 | for d in $RUNTIME_LIB_DIRS; do |
| @@ -49,6 +48,7 @@ done | |||
| 49 | 48 | ||
| 50 | echo "=== Packaging ===" | 49 | echo "=== Packaging ===" |
| 51 | for m in $MODULES; do | 50 | for m in $MODULES; do |
| 51 | [ "$m" = "$WAR_MODULE" ] && continue # ships as a WAR, below | ||
| 52 | case " $EXECUTABLES " in | 52 | case " $EXECUTABLES " in |
| 53 | *" $m "*) | 53 | *" $m "*) |
| 54 | "$JAR" --create --file "$DIST/$m.jar" --main-class "$(mainclass_of "$m")" \ | 54 | "$JAR" --create --file "$DIST/$m.jar" --main-class "$(mainclass_of "$m")" \ |
| @@ -72,6 +72,39 @@ done | |||
| 72 | 72 | ||
| 73 | [ -f README.pdf ] && cp README.pdf "$DIST/" | 73 | [ -f README.pdf ] && cp README.pdf "$DIST/" |
| 74 | 74 | ||
| 75 | echo "=== Exercise 3: WAR ===" | ||
| 76 | # The WAR carries everything the server needs; Tomcat only provides the servlet API. | ||
| 77 | WARDIR="$TMP/war" | ||
| 78 | rm -rf "$WARDIR" && mkdir -p "$WARDIR/WEB-INF/lib" | ||
| 79 | cp -r "build/classes/$WAR_MODULE" "$WARDIR/WEB-INF/classes" | ||
| 80 | for m in $(deps_of "$WAR_MODULE"); do | ||
| 81 | cp "$DIST/$m.jar" "$WARDIR/WEB-INF/lib/" | ||
| 82 | done | ||
| 83 | for d in $WAR_LIB_DIRS; do | ||
| 84 | for j in lib/"$d"/*.jar; do | ||
| 85 | is_shippable_jar "$j" || continue | ||
| 86 | cp "$j" "$WARDIR/WEB-INF/lib/" | ||
| 87 | done | ||
| 88 | done | ||
| 89 | EX3="$DIST/ex3" | ||
| 90 | mkdir -p "$EX3" | ||
| 91 | "$JAR" --create --file "$EX3/$WAR_NAME.war" -C "$WARDIR" . | ||
| 92 | echo " $EX3/$WAR_NAME.war" | ||
| 93 | "$JAR" --list --file "$EX3/$WAR_NAME.war" | grep 'WEB-INF/lib/.' | sed 's/^/ /' | ||
| 94 | |||
| 95 | echo "=== Exercise 3: client directory ===" | ||
| 96 | CDIR="$EX3/client" | ||
| 97 | mkdir -p "$CDIR/lib" | ||
| 98 | cp "$DIST/$CLIENT.jar" "$CDIR/" | ||
| 99 | for m in $(deps_of "$CLIENT"); do | ||
| 100 | cp "$DIST/$m.jar" "$CDIR/" | ||
| 101 | done | ||
| 102 | for d in $CLIENT_LIB_DIRS; do | ||
| 103 | cp -r "$DIST/lib/$d" "$CDIR/lib/" | ||
| 104 | done | ||
| 105 | cp "$DIST/run-${CLIENT#ui-}.bat" "$CDIR/" | ||
| 106 | ls "$CDIR" | sed 's/^/ /' | ||
| 107 | |||
| 75 | echo "=== Manifest as it actually landed in the jar ===" | 108 | echo "=== Manifest as it actually landed in the jar ===" |
| 76 | # Cheapest check that prevents a Level-0: if Main-Class or Class-Path didn't | 109 | # Cheapest check that prevents a Level-0: if Main-Class or Class-Path didn't |
| 77 | # survive, it surfaces here instead of on the grader's machine. | 110 | # survive, it surfaces here instead of on the grader's machine. |
diff --git a/tools/tomcat.sh b/tools/tomcat.sh new file mode 100644 index 0000000..05d38d2 --- /dev/null +++ b/tools/tomcat.sh | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | set -e | ||
| 4 | cd "$(dirname "$0")/.." | ||
| 5 | . tools/_util.sh | ||
| 6 | |||
| 7 | WAR="build/dist/ex3/$WAR_NAME.war" | ||
| 8 | [ -f "$WAR" ] || { | ||
| 9 | echo "No $WAR - run tools/package.sh first" | ||
| 10 | exit 1 | ||
| 11 | } | ||
| 12 | |||
| 13 | TOMCAT="${CATALINA_HOME:-$(ls -d /c/tomcat/apache-tomcat-* 2>/dev/null | sort -V | tail -n 1)}" | ||
| 14 | case "$(uname -s)" in | ||
| 15 | CYGWIN*|MINGW*|MSYS*) TOMCAT=$(cygpath -u "$TOMCAT" 2>/dev/null || echo "$TOMCAT") ;; | ||
| 16 | esac | ||
| 17 | [ -d "$TOMCAT/webapps" ] || { | ||
| 18 | echo "No Tomcat found. Set CATALINA_HOME to a Tomcat 10.1+ folder (the one holding webapps/)." | ||
| 19 | exit 1 | ||
| 20 | } | ||
| 21 | |||
| 22 | rm -rf "$TOMCAT/webapps/$WAR_NAME" "$TOMCAT/webapps/$WAR_NAME.war" | ||
| 23 | cp "$WAR" "$TOMCAT/webapps/" | ||
| 24 | |||
| 25 | echo "=== Tomcat: $TOMCAT ===" | ||
| 26 | echo " http://localhost:8080/$WAR_NAME/api/health" | ||
| 27 | |||
| 28 | case "$(uname -s)" in | ||
| 29 | CYGWIN*|MINGW*|MSYS*) | ||
| 30 | export CATALINA_HOME=$(cygpath -w "$TOMCAT") | ||
| 31 | export JAVA_HOME=$(cygpath -w "$JAVA_HOME_DIR") | ||
| 32 | exec cmd //c "$CATALINA_HOME\\bin\\catalina.bat" run | ||
| 33 | ;; | ||
| 34 | export CATALINA_HOME="$TOMCAT" | ||
| 35 | export JAVA_HOME="$JAVA_HOME_DIR" | ||
| 36 | exec "$TOMCAT/bin/catalina.sh" run | ||
| 37 | ;; | ||
| 38 | esac | ||