@echo off

@if "%1"=="create" goto create
@if "%1"=="remove" goto remove

echo "Usage: %0 {create|remove}"
goto end

:create
rem Set correct value to JBOSS_HOME
set JAVA_HOME=C:\jdk1.6.0
set JBOSS_HOME=C:\jboss-4.0.4.GA
echo %~dp0

set QWLIB=META-INF\lib

set CP=
set CP=%CP%;%QWLIB%\castor-0.9.7-xml.zip
set CP=%CP%;%QWLIB%\jakarta-regexp-1.4.jar
set CP=%CP%;%QWLIB%\qwcore-ejb.jar
set CP=%CP%;%QWLIB%\qwoss-ejb.jar
set CP=%CP%;%JBOSS_HOME%\lib\commons-logging.jar
set CP=%CP%;%JBOSS_HOME%\lib\endorsed\xercesImpl.jar
set CP=%CP%;%JBOSS_HOME%\client\jbossall-client.jar
set CP=%CP%;%JBOSS_HOME%\client\log4j.jar
set CP=%CP%;"%JBOSS_HOME%\client\javax.servlet.jar"

set JAVA_OPTS=-Dqx.mode=prod
set JAVA_OPTS=%JAVA_OPTS% -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
set JAVA_OPTS=%JAVA_OPTS% -Djava.naming.provider.url=jnp://localhost:1099
set JAVA_OPTS=%JAVA_OPTS% -Djava.naming.factory.url.pkgs=org.jboss.naming.client
set JAVA_OPTS=%JAVA_OPTS% -Dj2ee.clientName=qw-client

if not exist log4j.properties copy log4j.properties.example log4j.properties

JavaService -install "QScheduler_QWOSS" %JAVA_HOME%\jre\bin\server\jvm.dll -Xms128m -Xmx256m  %JAVA_OPTS% -Djava.class.path=%CP% -start com.queplix.core.modules.services.ServiceRunner  -current %~dp0
net start "QScheduler_QWOSS"
goto end

:remove
net stop "QScheduler_QWOSS"
JavaService -uninstall "QScheduler_QWOSS"
goto end

:end
