#!/bin/sh

echo "---------------------------"
echo "Starting Java Application"
echo "Main class   : ${MAIN_CLASS}"
echo "App JAR      : app.jar"
echo "Libs folder  : libs/"
echo "Detected JARs in libs/:"
find libs -type f -name "*.jar" -exec echo "  -> {}" \;

if [ ! -f app.jar ]; then
  echo "ERROR: app.jar not found. Ensure it is copied into the container."
  exit 1
fi

# Build classpath string
CLASSPATH="app.jar"
for jar in libs/*.jar; do
  CLASSPATH="$CLASSPATH:$jar"
done

echo "---------------------------"
echo "Executing: java -cp \"$CLASSPATH\" $MAIN_CLASS"
echo "---------------------------"

exec java -cp "$CLASSPATH" "$MAIN_CLASS"