@echo off

if exist ${installer:sys.installationDir} (
    cd ${installer:sys.installationDir}
)

SET OXYGEN_JAVA=java.exe
if exist "%JAVA_HOME%\bin\java.exe" set OXYGEN_JAVA="%JAVA_HOME%\bin\java.exe"
if exist "%~dp0\jre\bin\java.exe" SET OXYGEN_JAVA="%~dp0\jre\bin\java.exe"

REM This is the command line for the license server.

set CMDLINE=-jar lib/jetty-license-server.jar

REM This is the port to connect to.
REM If this param is missing, the default value is  8080
SET PORT=%1%

set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%

set Count=0
for %%a in (%*) do set /a Count+=1

echo Arguments %Count%

if %Count%==0 (
REM Since no arguments, at least warn the user.
echo ------- 
echo Usage: %NL%
echo   licenseServer.bat [port] %NL%
echo     port - the port of the license server %NL%
echo     If no argument is given the default port is "8080". 
echo No arguments are given - the default port is "8080". 
)

:cmd

if not ""%PORT%""=="""" (
  set CMDLINE=-Dcom.oxygenxml.licenseserver.port=%PORT% %CMDLINE%
)

REM Start the server.
%OXYGEN_JAVA% %CMDLINE%

REM pause the console once the program exits to keep the messages visible.
pause