@echo off
setLocal EnableDelayedExpansion
set p1="%1"
rem use JAVAWS_J_OPTIONS to pass java arguments, instead of -J opts for this script. This will be fixed in next releases
rem use JAVA_HOME to set path to JRE
set "NASHORN=lib\ext\nashorn.jar"
set "JRE=%~dp0.."
set "JAVA=%JRE%\bin\java"
set "LAUNCHER_FLAGS=-Xms8m"
set "CLASSNAME=net.sourceforge.jnlp.runtime.Boot"
set "PROGRAM_NAME=javaws"
set "CP=%JRE%\lib\rt.jar;%JRE%\lib\ext\jfxrt.jar"

set "BINARY_LOCATION=%JRE%\bin\%PROGRAM_NAME%.bat"
set "SPLASH_LOCATION=%JRE%\lib\ext\javaws_splash.png"
set "NETX_JAR=%JRE%\lib\ext\netx.jar"
set "PLUGIN_JAR=%JRE%\lib\ext\plugin.jar"
set "JSOBJECT_JAR=%JRE%\lib\ext\jsobject.jar"
set "LAUNCHER_BOOTCLASSPATH=-Xbootclasspath/a:!NETX_JAR!;!PLUGIN_JAR!;!JSOBJECT_JAR!"

set "SPLASH="-splash:%SPLASH_LOCATION:"=%""
set "LAUNCHER_BOOTCLASSPATH=%LAUNCHER_BOOTCLASSPATH%;%JRE%/%NASHORN%"

if "%PROGRAM_NAME%" == "javaws"  (
  goto javaws
) else (
  goto other
)

:javaws
if "%2" == "h" goto begin_with_args
mshta vbscript:createobject("wscript.shell").run("%~nx0 %p1% h",0)(window.close)&&exit

:other
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit

:begin_with_args
"%JAVA%" %SPLASH% "%LAUNCHER_BOOTCLASSPATH%" %LAUNCHER_FLAGS% %JAVAWS_J_OPTIONS% -classpath "%CP%" "-Dicedtea-web.bin.name=%PROGRAM_NAME%" "-Dicedtea-web.bin.location=%BINARY_LOCATION%" "%CLASSNAME%" %1
exit

:begin
"%JAVA%" %SPLASH% "%LAUNCHER_BOOTCLASSPATH%" %LAUNCHER_FLAGS% %JAVAWS_J_OPTIONS% -classpath "%CP%" "-Dicedtea-web.bin.name=%PROGRAM_NAME%" "-Dicedtea-web.bin.location=%BINARY_LOCATION%" "%CLASSNAME%"
exit
