@echo off

set SRCEXE=financial_service_test

REM Get the Java version

set KEY="HKLM\SOFTWARE\JavaSoft\Java Runtime Environment"
set VALUE=CurrentVersion
reg query %KEY% /v %VALUE% >nul 2>&1 || (
  echo ERROR: JDK not installed 
  exit /b 1
)

set JRE_VERSION=
for /f "tokens=2,*" %%a in ('reg query %KEY% /v %VALUE% ^| findstr %VALUE%') do (
  set JRE_VERSION=%%b
)

REM Get the JavaHome

set KEY="HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\%JRE_VERSION%"
set VALUE=JavaHome
reg query %KEY% /v %VALUE% >nul 2>&1 || (
  echo ERROR: JavaHome not found
  exit /b 1
)

set JAVAHOME=
for /f "tokens=2,*" %%a in ('reg query %KEY% /v %VALUE% ^| findstr %VALUE%') do (
  set JAVAHOME=%%b
)

"%JAVAHOME%\bin\java" -jar Java\%SRCEXE%.jar

REM Free the resources

set JAVAHOME=
set JRE_VERSION=
set KEY=
set SRCEXE=
set VALUE=
