1@echo off 2rem ------------------------------------------------------------------------- 3rem JBoss Bootstrap Script for Windows 4rem ------------------------------------------------------------------------- 5 6rem Use --debug to activate debug mode with an optional argument to specify the port 7rem Usage : standalone.bat --debug 8rem standalone.bat --debug 9797 9 10@if not "%ECHO%" == "" echo %ECHO% 11setlocal 12 13rem By default debug mode is disable. 14set DEBUG_MODE=false 15set DEBUG_PORT_VAR=8787 16rem Set to all parameters by default 17set "SERVER_OPTS=%*" 18 19 20if NOT "x%DEBUG%" == "x" ( 21 set "DEBUG_MODE=%DEBUG% 22) 23 24rem Get the program name before using shift as the command modify the variable ~nx0 25if "%OS%" == "Windows_NT" ( 26 set "PROGNAME=%~nx0%" 27) else ( 28 set "PROGNAME=standalone.bat" 29) 30 31if "%OS%" == "Windows_NT" ( 32 set "DIRNAME=%~dp0%" 33) else ( 34 set DIRNAME=.\ 35) 36setlocal EnableDelayedExpansion 37rem check for the security manager system property 38echo(!SERVER_OPTS! | findstr /r /c:"-Djava.security.manager" > nul 39if not errorlevel == 1 ( 40 echo ERROR: The use of -Djava.security.manager has been removed. Please use the -secmgr command line argument or SECMGR=true environment variable. 41 GOTO :EOF 42) 43setlocal DisableDelayedExpansion 44 45rem Read command-line args, the ~ removes the quotes from the parameter 46:READ-ARGS 47if "%~1" == "" ( 48 goto MAIN 49) else if "%~1" == "--debug" ( 50 goto READ-DEBUG-PORT 51) else if "%~1" == "-secmgr" ( 52 set SECMGR=true 53) 54shift 55goto READ-ARGS 56 57:READ-DEBUG-PORT 58set "DEBUG_MODE=true" 59set DEBUG_ARG="%2" 60if not %DEBUG_ARG% == "" ( 61 if x%DEBUG_ARG:-=%==x%DEBUG_ARG% ( 62 shift 63 set DEBUG_PORT_VAR=%DEBUG_ARG% 64 ) 65 shift 66 goto READ-ARGS 67) 68 69:MAIN 70rem $Id$ 71) 72 73pushd "%DIRNAME%.." 74set "RESOLVED_JBOSS_HOME=%CD%" 75popd 76 77if "x%JBOSS_HOME%" == "x" ( 78 set "JBOSS_HOME=%RESOLVED_JBOSS_HOME%" 79) 80 81pushd "%JBOSS_HOME%" 82set "SANITIZED_JBOSS_HOME=%CD%" 83popd 84 85if /i "%RESOLVED_JBOSS_HOME%" NEQ "%SANITIZED_JBOSS_HOME%" ( 86 echo. 87 echo WARNING: JBOSS_HOME may be pointing to a different installation - unpredictable results may occur. 88 echo. 89 echo JBOSS_HOME: "%JBOSS_HOME%" 90 echo. 91) 92 93rem Read an optional configuration file. 94if "x%STANDALONE_CONF%" == "x" ( 95 set "STANDALONE_CONF=%DIRNAME%standalone.conf.bat" 96) 97if exist "%STANDALONE_CONF%" ( 98 echo Calling "%STANDALONE_CONF%" 99 call "%STANDALONE_CONF%" %* 100) else ( 101 echo Config file not found "%STANDALONE_CONF%" 102) 103 104if NOT "x%DEBUG_PORT%" == "x" ( 105 set DEBUG_PORT_VAR=%DEBUG_PORT% 106) 107 108if NOT "x%GC_LOG%" == "x" ( 109 set "GC_LOG=%GC_LOG% 110) 111 112rem Set debug settings if not already set 113if "%DEBUG_MODE%" == "true" ( 114 echo "%JAVA_OPTS%" | findstr /I "\-agentlib:jdwp" > nul 115 if errorlevel == 1 ( 116 set "JAVA_OPTS=%JAVA_OPTS% -agentlib:jdwp=transport=dt_socket,address=%DEBUG_PORT_VAR%,server=y,suspend=n" 117 ) else ( 118 echo Debug already enabled in JAVA_OPTS, ignoring --debug argument 119 ) 120) 121 122rem Setup JBoss specific properties 123set "JAVA_OPTS=-Dprogram.name=%PROGNAME% %JAVA_OPTS%" 124 125if "x%JAVA_HOME%" == "x" ( 126 set JAVA=java 127 echo JAVA_HOME is not set. Unexpected results may occur. 128 echo Set JAVA_HOME to the directory of your local JDK to avoid this message. 129) else ( 130 if not exist "%JAVA_HOME%" ( 131 echo JAVA_HOME "%JAVA_HOME%" path doesn't exist 132 goto END 133 ) else ( 134 if not exist "%JAVA_HOME%\bin\java.exe" ( 135 echo "%JAVA_HOME%\bin\java.exe" does not exist 136 goto END_NO_PAUSE 137 ) 138 echo Setting JAVA property to "%JAVA_HOME%\bin\java" 139 set "JAVA=%JAVA_HOME%\bin\java" 140 ) 141) 142 143"%JAVA%" --add-modules=java.se -version >nul 2>&1 && (set MODULAR_JDK=true) || (set MODULAR_JDK=false) 144 145if not "%PRESERVE_JAVA_OPTS%" == "true" ( 146 rem Add -client to the JVM options, if supported (32 bit VM), and not overriden 147 echo "%JAVA_OPTS%" | findstr /I \-server > nul 148 if errorlevel == 1 ( 149 "%JAVA%" -client -version 2>&1 | findstr /I /C:"Client VM" > nul 150 if not errorlevel == 1 ( 151 set "JAVA_OPTS=-client %JAVA_OPTS%" 152 ) 153 ) 154) 155 156rem Find jboss-modules.jar, or we can't continue 157if exist "%JBOSS_HOME%\jboss-modules.jar" ( 158 set "RUNJAR=%JBOSS_HOME%\jboss-modules.jar" 159) else ( 160 echo Could not locate "%JBOSS_HOME%\jboss-modules.jar". 161 echo Please check that you are in the bin directory when running this script. 162 goto END 163) 164 165rem Setup JBoss specific properties 166 167rem Setup directories, note directories with spaces do not work 168setlocal EnableDelayedExpansion 169set "CONSOLIDATED_OPTS=%JAVA_OPTS% %SERVER_OPTS%" 170set baseDirFound=false 171set configDirFound=false 172set logDirFound=false 173for %%a in (!CONSOLIDATED_OPTS!) do ( 174 if !baseDirFound! == true ( 175 set "JBOSS_BASE_DIR=%%~a" 176 set baseDirFound=false 177 ) 178 if !configDirFound! == true ( 179 set "JBOSS_CONFIG_DIR=%%~a" 180 set configDirFound=false 181 ) 182 if !logDirFound! == true ( 183 set "JBOSS_LOG_DIR=%%~a" 184 set logDirFound=false 185 ) 186 if "%%~a" == "-Djboss.server.base.dir" ( 187 set baseDirFound=true 188 ) 189 if "%%~a" == "-Djboss.server.config.dir" ( 190 set configDirFound=true 191 ) 192 if "%%~a" == "-Djboss.server.log.dir" ( 193 set logDirFound=true 194 ) 195) 196 197rem If the -Djava.security.manager is found, enable the -secmgr and include a bogus security manager for JBoss Modules to replace 198echo(!JAVA_OPTS! | findstr /r /c:"-Djava.security.manager" > nul && ( 199 echo ERROR: The use of -Djava.security.manager has been removed. Please use the -secmgr command line argument or SECMGR=true environment variable. 200 GOTO :EOF 201) 202setlocal DisableDelayedExpansion 203 204rem Set default module root paths 205if "x%JBOSS_MODULEPATH%" == "x" ( 206 set "JBOSS_MODULEPATH=%JBOSS_HOME%\modules" 207) 208 209rem Set the standalone base dir 210if "x%JBOSS_BASE_DIR%" == "x" ( 211 set "JBOSS_BASE_DIR=%JBOSS_HOME%\standalone" 212) 213rem Set the standalone log dir 214if "x%JBOSS_LOG_DIR%" == "x" ( 215 set "JBOSS_LOG_DIR=%JBOSS_BASE_DIR%\log" 216) 217rem Set the standalone configuration dir 218if "x%JBOSS_CONFIG_DIR%" == "x" ( 219 set "JBOSS_CONFIG_DIR=%JBOSS_BASE_DIR%\configuration" 220) 221 222if not "%PRESERVE_JAVA_OPTS%" == "true" ( 223 if "%GC_LOG%" == "true" ( 224 rem Add rotating GC logs, if supported, and not already defined 225 echo "%JAVA_OPTS%" | findstr /I "\-verbose:gc" > nul 226 if errorlevel == 1 ( 227 rem Back up any prior logs 228 move /y "%JBOSS_LOG_DIR%\gc.log.1" "%JBOSS_LOG_DIR%\backupgc.log.1" > nul 2>&1 229 move /y "%JBOSS_LOG_DIR%\gc.log.0" "%JBOSS_LOG_DIR%\backupgc.log.0" > nul 2>&1 230 move /y "%JBOSS_LOG_DIR%\gc.log.2" "%JBOSS_LOG_DIR%\backupgc.log.2" > nul 2>&1 231 move /y "%JBOSS_LOG_DIR%\gc.log.3" "%JBOSS_LOG_DIR%\backupgc.log.3" > nul 2>&1 232 move /y "%JBOSS_LOG_DIR%\gc.log.4" "%JBOSS_LOG_DIR%\backupgc.log.4" > nul 2>&1 233 move /y "%JBOSS_LOG_DIR%\gc.log.*.current" "%JBOSS_LOG_DIR%\backupgc.log.current" > nul 2>&1 234 235 "%JAVA%" -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -Xloggc:"%JBOSS_LOG_DIR%\gc.log" -XX:-TraceClassUnloading -version > nul 2>&1 236 if not errorlevel == 1 ( 237 if not exist "%JBOSS_LOG_DIR" > nul 2>&1 ( 238 mkdir "%JBOSS_LOG_DIR%" 239 ) 240 set JAVA_OPTS=%JAVA_OPTS% -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -Xloggc:"%JBOSS_LOG_DIR%\gc.log" -XX:GCLogFileSize=3M -XX:-TraceClassUnloading 241 ) 242 ) 243 ) 244 245 rem set default modular jvm parameters 246 setlocal EnableDelayedExpansion 247 call "!DIRNAME!common.bat" :setDefaultModularJvmOptions "!JAVA_OPTS!" 248 set "JAVA_OPTS=!JAVA_OPTS! !DEFAULT_MODULAR_JVM_OPTIONS!" 249 setlocal DisableDelayedExpansion 250) 251 252 253 254 255rem Set the module options 256set "MODULE_OPTS=" 257if "%SECMGR%" == "true" ( 258 set "MODULE_OPTS=-secmgr" 259) 260 261echo =============================================================================== 262echo. 263echo JBoss Bootstrap Environment 264echo. 265echo JBOSS_HOME: "%JBOSS_HOME%" 266echo. 267echo JAVA: "%JAVA%" 268echo. 269echo JAVA_OPTS: "%JAVA_OPTS%" 270echo. 271echo =============================================================================== 272echo. 273 274:RESTART 275 "%JAVA%" %JAVA_OPTS% ^ 276 "-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\server.log" ^ 277 "-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/logging.properties" ^ 278 -jar "%JBOSS_HOME%\jboss-modules.jar" ^ 279 %MODULE_OPTS% ^ 280 -mp "%JBOSS_MODULEPATH%" ^ 281 org.jboss.as.standalone ^ 282 "-Djboss.home.dir=%JBOSS_HOME%" ^ 283 %SERVER_OPTS% 284 285if %errorlevel% equ 10 ( 286 goto RESTART 287) 288 289:END 290if "x%NOPAUSE%" == "x" pause 291 292:END_NO_PAUSE 293