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 222setlocal EnableDelayedExpansion 223call "!DIRNAME!common.bat" :setModularJdk 224setlocal DisableDelayedExpansion 225 226if not "%PRESERVE_JAVA_OPT%" == "true" ( 227 if "%GC_LOG%" == "true" ( 228 if not exist "%JBOSS_LOG_DIR%" > nul 2>&1 ( 229 mkdir "%JBOSS_LOG_DIR%" 230 ) 231 rem Add rotating GC logs, if supported, and not already defined 232 echo "%JAVA_OPTS%" | findstr /I "\-Xlog:*gc" > nul 233 if errorlevel == 1 ( 234 rem Back up any prior logs 235 move /y "%JBOSS_LOG_DIR%\gc.log" "%JBOSS_LOG_DIR%\backupgc.log" > nul 2>&1 236 move /y "%JBOSS_LOG_DIR%\gc.log.0" "%JBOSS_LOG_DIR%\backupgc.log.0" > nul 2>&1 237 move /y "%JBOSS_LOG_DIR%\gc.log.1" "%JBOSS_LOG_DIR%\backupgc.log.1" > nul 2>&1 238 move /y "%JBOSS_LOG_DIR%\gc.log.2" "%JBOSS_LOG_DIR%\backupgc.log.2" > nul 2>&1 239 move /y "%JBOSS_LOG_DIR%\gc.log.3" "%JBOSS_LOG_DIR%\backupgc.log.3" > nul 2>&1 240 move /y "%JBOSS_LOG_DIR%\gc.log.4" "%JBOSS_LOG_DIR%\backupgc.log.4" > nul 2>&1 241 move /y "%JBOSS_LOG_DIR%\gc.log.*.current" "%JBOSS_LOG_DIR%\backupgc.log.current" > nul 2>&1 242 243 setlocal EnableDelayedExpansion 244 if "!MODULAR_JDK!" == "true" ( 245 set TMP_PARAM=-Xlog:gc*:file="\"%JBOSS_LOG_DIR%\gc.log\"":time,uptimemillis:filecount=5,filesize=3M 246 ) else ( 247 set TMP_PARAM=-verbose:gc -Xloggc:"%JBOSS_LOG_DIR%\gc.log" -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -XX:-TraceClassUnloading 248 ) 249 "%JAVA%" !TMP_PARAM! -version > nul 2>&1 250 if not errorlevel == 1 ( 251 set JAVA_OPTS=%JAVA_OPTS% !TMP_PARAM! 252 ) 253 rem Remove the gc.log file from the -version check 254 del /F /Q "%JBOSS_LOG_DIR%\gc.log" > nul 2>&1 255 ) 256 setlocal DisableDelayedExpansion 257 ) 258 259 rem set default modular jvm parameters 260 setlocal EnableDelayedExpansion 261 call "!DIRNAME!common.bat" :setDefaultModularJvmOptions !JAVA_OPTS! 262 set "JAVA_OPTS=!JAVA_OPTS! !DEFAULT_MODULAR_JVM_OPTIONS!" 263 setlocal DisableDelayedExpansion 264) 265 266 267 268 269rem Set the module options 270set "MODULE_OPTS=" 271if "%SECMGR%" == "true" ( 272 set "MODULE_OPTS=-secmgr" 273) 274 275echo =============================================================================== 276echo. 277echo JBoss Bootstrap Environment 278echo. 279echo JBOSS_HOME: "%JBOSS_HOME%" 280echo. 281echo JAVA: "%JAVA%" 282echo. 283echo JAVA_OPTS: "%JAVA_OPTS%" 284echo. 285echo =============================================================================== 286echo. 287 288:RESTART 289 "%JAVA%" %JAVA_OPTS% ^ 290 "-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\server.log" ^ 291 "-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/logging.properties" ^ 292 -jar "%JBOSS_HOME%\jboss-modules.jar" ^ 293 %MODULE_OPTS% ^ 294 -mp "%JBOSS_MODULEPATH%" ^ 295 org.jboss.as.standalone ^ 296 "-Djboss.home.dir=%JBOSS_HOME%" ^ 297 %SERVER_OPTS% 298 299if %errorlevel% equ 10 ( 300 goto RESTART 301) 302 303:END 304if "x%NOPAUSE%" == "x" pause 305 306:END_NO_PAUSE 307