@echo off

REM Set the path to the JAR file
set JAR_PATH=build\libs\MyKotlinProject-1.0-SNAPSHOT.jar

REM Function to check if Java is installed
where java >nul 2>nul
if %errorlevel% neq 0 (
    echo Error: Java is not installed. Please install Java to run this program.
    exit /b 1
)

REM Check if the JAR file exists
if not exist "%JAR_PATH%" (
    echo JAR file not found at %JAR_PATH%.
    echo Building the project...
    gradlew build
    if %errorlevel% neq 0 (
        echo Error: Build failed.
        exit /b 1
    )
)

REM Run the Java command
java -jar %JAR_PATH% %*
