@echo off

setlocal

if NOT DEFINED JAVA_HOME goto err
if NOT DEFINED APP_HOME set APP_HOME=%~dp0..

REM Build the class path for the java application

REM Ensure that any user defined CLASSPATH variables are not used on startup
set CLASSPATH=%APP_HOME%\conf

REM For each jar in the APP_HOME lib directory call append to build the CLASSPATH variable.
for %%i in ("%APP_HOME%\lib\*.jar") do call :append "%%i"
goto okClasspath

:append
set CLASSPATH=%CLASSPATH%;%1
goto :eof

:okClasspath
REM Include the build\classes directory so it works in development
set CLASSPATH=%CLASSPATH%;"%APP_HOME%\divconq.template\bin";

set MAINCLASS=%2

echo Command %1

if %1 == configure set MAINCLASS="divconq.tool.Configure"
if %1 == sync set MAINCLASS="divconq.tool.Sync"
if %1 == testdb set MAINCLASS="divconq.test.TestDb"
if %1 == etlutil set MAINCLASS="etime.util.Main"

echo Starting Hub
"%JAVA_HOME%\bin\java" -cp %CLASSPATH% %MAINCLASS%
goto finally

:err
echo JAVA_HOME environment variable must be set!
pause

:finally

endlocal
