#!/bin/bash

# run.sh
# Andrew Davison, ad@fivedots.coe.psu.ac.th, Feb. 2023

if [ "$1" = "" ]
then
  echo "No file name supplied"
  exit 1
fi

# assume the Jars are in libs folder
libs="libs/"
if ! [ -e $libs ]
then
  echo "No libs folder found"
  exit 1
fi

path="$(pwd)"
# echo "$path"
# useful with java's -Djava.library.path


# strip off any extension, such as .class
fnm="${1%%.*}"
# echo $fnm

echo "Using:"
for f in $(ls $libs) 
do
  echo "  $f"
done

echo "Executing $fnm..."

# get all the arguments after $1
tail="${@:2}"
# echo "$tail"

# clear
java -cp "$libs/*:." $fnm $tail 2> out.txt

cat out.txt

echo "Finished."

