#!/bin/bash
# 20240123

DN=$(dirname "$0")
JAVAPATH="$DN/jre/bin"
CLASSPATH="$DN"

# Choose the appropriate Java command based on the existence of jre folder
if [ -f "$DN/jre/lib/rt.jar" ]; then
    CMD="$JAVAPATH/java"
else
    CMD="java"
fi

# Use a more robust way to find JAR files
find "$DN/{lib,ext,ext/drivers}" -name '*.jar' -exec CLASSPATH="$CLASSPATH:{};" \;

# Use double quotes around variables to handle spaces in paths
$CMD -cp "$CLASSPATH" -Djava.library.path="$DN/jni" -Dterminal.dir="$DN" -Dsun.java2d.opengl=true -Xmx256m ru.softlogic.app.Main scan
