From da4f3ceb1fc1f317a3cca788b6c9b78ffab12de2 Mon Sep 17 00:00:00 2001 From: Kostya Date: Tue, 13 Oct 2026 19:19:40 +0300 Subject: 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. --- tools/_util.sh | 8 ++++++++ tools/package.sh | 37 +++++++++++++++++++++++++++++++++++-- tools/tomcat.sh | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 tools/tomcat.sh (limited to 'tools') 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" MAINCLASS_ui_desktop="market.guess.ui.desktop.Launcher" MAINCLASS_ui_client="market.guess.ui.client.Launcher" +# Exercise 3 submission: one WAR for Tomcat's webapps/ and a self-contained client directory. +# The WAR is named after the context path the client expects (/guess-market). +WAR_MODULE="server" +WAR_NAME="guess-market" +WAR_LIB_DIRS="gson jaxb" +CLIENT="ui-client" +CLIENT_LIB_DIRS="gson openjfx okhttp" + JAVA_HOME_DIR=$(java -XshowSettings:properties -version 2>&1 | tr -d '\r' | sed -n 's/^ *java\.home = //p') case "$(uname -s)" in 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 ===" # this line is the entire classpath at runtime. for e in $EXECUTABLES; do CPLINE="" - for m in $MODULES; do - [ "$m" = "$e" ] && continue + for m in $(deps_of "$e"); do CPLINE="$CPLINE${CPLINE:+ }$m.jar" done for d in $RUNTIME_LIB_DIRS; do @@ -49,6 +48,7 @@ done echo "=== Packaging ===" for m in $MODULES; do + [ "$m" = "$WAR_MODULE" ] && continue # ships as a WAR, below case " $EXECUTABLES " in *" $m "*) "$JAR" --create --file "$DIST/$m.jar" --main-class "$(mainclass_of "$m")" \ @@ -72,6 +72,39 @@ done [ -f README.pdf ] && cp README.pdf "$DIST/" +echo "=== Exercise 3: WAR ===" +# The WAR carries everything the server needs; Tomcat only provides the servlet API. +WARDIR="$TMP/war" +rm -rf "$WARDIR" && mkdir -p "$WARDIR/WEB-INF/lib" +cp -r "build/classes/$WAR_MODULE" "$WARDIR/WEB-INF/classes" +for m in $(deps_of "$WAR_MODULE"); do + cp "$DIST/$m.jar" "$WARDIR/WEB-INF/lib/" +done +for d in $WAR_LIB_DIRS; do + for j in lib/"$d"/*.jar; do + is_shippable_jar "$j" || continue + cp "$j" "$WARDIR/WEB-INF/lib/" + done +done +EX3="$DIST/ex3" +mkdir -p "$EX3" +"$JAR" --create --file "$EX3/$WAR_NAME.war" -C "$WARDIR" . +echo " $EX3/$WAR_NAME.war" +"$JAR" --list --file "$EX3/$WAR_NAME.war" | grep 'WEB-INF/lib/.' | sed 's/^/ /' + +echo "=== Exercise 3: client directory ===" +CDIR="$EX3/client" +mkdir -p "$CDIR/lib" +cp "$DIST/$CLIENT.jar" "$CDIR/" +for m in $(deps_of "$CLIENT"); do + cp "$DIST/$m.jar" "$CDIR/" +done +for d in $CLIENT_LIB_DIRS; do + cp -r "$DIST/lib/$d" "$CDIR/lib/" +done +cp "$DIST/run-${CLIENT#ui-}.bat" "$CDIR/" +ls "$CDIR" | sed 's/^/ /' + echo "=== Manifest as it actually landed in the jar ===" # Cheapest check that prevents a Level-0: if Main-Class or Class-Path didn't # 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 @@ +#!/bin/bash + +set -e +cd "$(dirname "$0")/.." +. tools/_util.sh + +WAR="build/dist/ex3/$WAR_NAME.war" +[ -f "$WAR" ] || { + echo "No $WAR - run tools/package.sh first" + exit 1 +} + +TOMCAT="${CATALINA_HOME:-$(ls -d /c/tomcat/apache-tomcat-* 2>/dev/null | sort -V | tail -n 1)}" +case "$(uname -s)" in + CYGWIN*|MINGW*|MSYS*) TOMCAT=$(cygpath -u "$TOMCAT" 2>/dev/null || echo "$TOMCAT") ;; +esac +[ -d "$TOMCAT/webapps" ] || { + echo "No Tomcat found. Set CATALINA_HOME to a Tomcat 10.1+ folder (the one holding webapps/)." + exit 1 +} + +rm -rf "$TOMCAT/webapps/$WAR_NAME" "$TOMCAT/webapps/$WAR_NAME.war" +cp "$WAR" "$TOMCAT/webapps/" + +echo "=== Tomcat: $TOMCAT ===" +echo " http://localhost:8080/$WAR_NAME/api/health" + +case "$(uname -s)" in + CYGWIN*|MINGW*|MSYS*) + export CATALINA_HOME=$(cygpath -w "$TOMCAT") + export JAVA_HOME=$(cygpath -w "$JAVA_HOME_DIR") + exec cmd //c "$CATALINA_HOME\\bin\\catalina.bat" run + ;; + export CATALINA_HOME="$TOMCAT" + export JAVA_HOME="$JAVA_HOME_DIR" + exec "$TOMCAT/bin/catalina.sh" run + ;; +esac -- cgit v1.2.3