Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 1 | @echo off |
| 2 | rem |
| 3 | rem |
| 4 | rem Licensed to the Apache Software Foundation (ASF) under one or more |
| 5 | rem contributor license agreements. See the NOTICE file distributed with |
| 6 | rem this work for additional information regarding copyright ownership. |
| 7 | rem The ASF licenses this file to You under the Apache License, Version 2.0 |
| 8 | rem (the "License"); you may not use this file except in compliance with |
| 9 | rem the License. You may obtain a copy of the License at |
| 10 | rem |
| 11 | rem http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | rem |
| 13 | rem Unless required by applicable law or agreed to in writing, software |
| 14 | rem distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | rem See the License for the specific language governing permissions and |
| 17 | rem limitations under the License. |
| 18 | rem |
Guillaume Nodet | 11b422f | 2010-04-30 14:49:11 +0000 | [diff] [blame] | 19 | rem |
Guillaume Nodet | 874ecc8 | 2009-05-04 07:56:47 +0000 | [diff] [blame] | 20 | rem $Id: karaf.bat 979 2005-11-30 22:50:55Z bsnyder $ |
Guillaume Nodet | 11b422f | 2010-04-30 14:49:11 +0000 | [diff] [blame] | 21 | rem |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 22 | |
| 23 | if not "%ECHO%" == "" echo %ECHO% |
| 24 | |
| 25 | setlocal |
| 26 | set DIRNAME=%~dp0% |
| 27 | set PROGNAME=%~nx0% |
| 28 | set ARGS=%* |
| 29 | |
| 30 | title Karaf |
| 31 | |
| 32 | goto BEGIN |
| 33 | |
| 34 | :warn |
| 35 | echo %PROGNAME%: %* |
| 36 | goto :EOF |
| 37 | |
| 38 | :BEGIN |
| 39 | |
| 40 | rem # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 41 | |
| 42 | if not "%KARAF_HOME%" == "" ( |
| 43 | call :warn Ignoring predefined value for KARAF_HOME |
| 44 | ) |
| 45 | set KARAF_HOME=%DIRNAME%.. |
| 46 | if not exist "%KARAF_HOME%" ( |
| 47 | call :warn KARAF_HOME is not valid: %KARAF_HOME% |
| 48 | goto END |
| 49 | ) |
| 50 | |
| 51 | if not "%KARAF_BASE%" == "" ( |
| 52 | if not exist "%KARAF_BASE%" ( |
| 53 | call :warn KARAF_BASE is not valid: %KARAF_BASE% |
| 54 | goto END |
| 55 | ) |
| 56 | ) |
| 57 | if "%KARAF_BASE%" == "" ( |
| 58 | set KARAF_BASE=%KARAF_HOME% |
| 59 | ) |
| 60 | |
| 61 | set LOCAL_CLASSPATH=%CLASSPATH% |
| 62 | set DEFAULT_JAVA_OPTS=-server -Xmx512M -Dderby.system.home="%KARAF_BASE%\data\derby" -Dderby.storage.fileSyncTransactionLog=true -Dcom.sun.management.jmxremote |
| 63 | set CLASSPATH=%LOCAL_CLASSPATH%;%KARAF_BASE%\conf |
| 64 | set DEFAULT_JAVA_DEBUG_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 |
| 65 | |
| 66 | if "%LOCAL_CLASSPATH%" == "" goto :KARAF_CLASSPATH_EMPTY |
| 67 | set CLASSPATH=%LOCAL_CLASSPATH%;%KARAF_BASE%\conf |
| 68 | goto :KARAF_CLASSPATH_END |
| 69 | :KARAF_CLASSPATH_EMPTY |
| 70 | set CLASSPATH=%KARAF_BASE%\conf |
| 71 | :KARAF_CLASSPATH_END |
| 72 | |
| 73 | rem Setup Karaf Home |
| 74 | if exist "%KARAF_HOME%\conf\karaf-rc.cmd" call %KARAF_HOME%\conf\karaf-rc.cmd |
| 75 | if exist "%HOME%\karaf-rc.cmd" call %HOME%\karaf-rc.cmd |
| 76 | |
| 77 | rem Support for loading native libraries |
| 78 | set PATH=%PATH%;%KARAF_BASE%\lib;%KARAF_HOME%\lib |
| 79 | |
| 80 | rem Setup the Java Virtual Machine |
| 81 | if not "%JAVA%" == "" goto :Check_JAVA_END |
Guillaume Nodet | 11b422f | 2010-04-30 14:49:11 +0000 | [diff] [blame] | 82 | if not "%JAVA_HOME%" == "" goto :TryJDKEnd |
| 83 | call :warn JAVA_HOME not set; results may vary |
| 84 | :TryJRE |
| 85 | start /w regedit /e __reg1.txt "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" |
| 86 | if not exist __reg1.txt goto :TryJDK |
| 87 | type __reg1.txt | find "CurrentVersion" > __reg2.txt |
| 88 | if errorlevel 1 goto :TryJDK |
| 89 | for /f "tokens=2 delims==" %%x in (__reg2.txt) do set JavaTemp=%%~x |
| 90 | if errorlevel 1 goto :TryJDK |
| 91 | set JavaTemp=%JavaTemp%## |
| 92 | set JavaTemp=%JavaTemp: ##=##% |
| 93 | set JavaTemp=%JavaTemp: ##=##% |
| 94 | set JavaTemp=%JavaTemp: ##=##% |
| 95 | set JavaTemp=%JavaTemp: ##=##% |
| 96 | set JavaTemp=%JavaTemp: ##=##% |
| 97 | set JavaTemp=%JavaTemp:##=% |
| 98 | del __reg1.txt |
| 99 | del __reg2.txt |
| 100 | start /w regedit /e __reg1.txt "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\%JavaTemp%" |
| 101 | if not exist __reg1.txt goto :TryJDK |
| 102 | type __reg1.txt | find "JavaHome" > __reg2.txt |
| 103 | if errorlevel 1 goto :TryJDK |
| 104 | for /f "tokens=2 delims==" %%x in (__reg2.txt) do set JAVA_HOME=%%~x |
| 105 | if errorlevel 1 goto :TryJDK |
| 106 | del __reg1.txt |
| 107 | del __reg2.txt |
| 108 | goto TryJDKEnd |
| 109 | :TryJDK |
| 110 | start /w regedit /e __reg1.txt "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit" |
| 111 | if not exist __reg1.txt ( |
| 112 | call :warn Unable to retrieve JAVA_HOME |
| 113 | goto END |
| 114 | ) |
| 115 | type __reg1.txt | find "CurrentVersion" > __reg2.txt |
| 116 | if errorlevel 1 ( |
| 117 | call :warn Unable to retrieve JAVA_HOME |
| 118 | goto END |
| 119 | ) |
| 120 | for /f "tokens=2 delims==" %%x in (__reg2.txt) do set JavaTemp=%%~x |
| 121 | if errorlevel 1 ( |
| 122 | call :warn Unable to retrieve JAVA_HOME |
| 123 | goto END |
| 124 | ) |
| 125 | set JavaTemp=%JavaTemp%## |
| 126 | set JavaTemp=%JavaTemp: ##=##% |
| 127 | set JavaTemp=%JavaTemp: ##=##% |
| 128 | set JavaTemp=%JavaTemp: ##=##% |
| 129 | set JavaTemp=%JavaTemp: ##=##% |
| 130 | set JavaTemp=%JavaTemp: ##=##% |
| 131 | set JavaTemp=%JavaTemp:##=% |
| 132 | del __reg1.txt |
| 133 | del __reg2.txt |
| 134 | start /w regedit /e __reg1.txt "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\%JavaTemp%" |
| 135 | if not exist __reg1.txt ( |
| 136 | call :warn Unable to retrieve JAVA_HOME from JDK |
| 137 | goto END |
| 138 | ) |
| 139 | type __reg1.txt | find "JavaHome" > __reg2.txt |
| 140 | if errorlevel 1 ( |
| 141 | call :warn Unable to retrieve JAVA_HOME |
| 142 | goto END |
| 143 | ) |
| 144 | for /f "tokens=2 delims==" %%x in (__reg2.txt) do set JAVA_HOME=%%~x |
| 145 | if errorlevel 1 ( |
| 146 | call :warn Unable to retrieve JAVA_HOME |
| 147 | goto END |
| 148 | ) |
| 149 | del __reg1.txt |
| 150 | del __reg2.txt |
| 151 | :TryJDKEnd |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 152 | if not exist "%JAVA_HOME%" ( |
| 153 | call :warn JAVA_HOME is not valid: "%JAVA_HOME%" |
| 154 | goto END |
| 155 | ) |
Guillaume Nodet | 11b422f | 2010-04-30 14:49:11 +0000 | [diff] [blame] | 156 | set JAVA=%JAVA_HOME%\bin\java |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 157 | :Check_JAVA_END |
| 158 | |
| 159 | if "%JAVA_OPTS%" == "" set JAVA_OPTS=%DEFAULT_JAVA_OPTS% |
| 160 | |
| 161 | if "%KARAF_DEBUG%" == "" goto :KARAF_DEBUG_END |
| 162 | rem Use the defaults if JAVA_DEBUG_OPTS was not set |
| 163 | if "%JAVA_DEBUG_OPTS%" == "" set JAVA_DEBUG_OPTS=%DEFAULT_JAVA_DEBUG_OPTS% |
Guillaume Nodet | 11b422f | 2010-04-30 14:49:11 +0000 | [diff] [blame] | 164 | |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 165 | set "JAVA_OPTS=%JAVA_DEBUG_OPTS% %JAVA_OPTS%" |
| 166 | call :warn Enabling Java debug options: %JAVA_DEBUG_OPTS% |
| 167 | :KARAF_DEBUG_END |
| 168 | |
| 169 | if "%KARAF_PROFILER%" == "" goto :KARAF_PROFILER_END |
| 170 | set KARAF_PROFILER_SCRIPT=%KARAF_HOME%\conf\profiler\%KARAF_PROFILER%.cmd |
Guillaume Nodet | 11b422f | 2010-04-30 14:49:11 +0000 | [diff] [blame] | 171 | |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 172 | if exist "%KARAF_PROFILER_SCRIPT%" goto :KARAF_PROFILER_END |
| 173 | call :warn Missing configuration for profiler '%KARAF_PROFILER%': %KARAF_PROFILER_SCRIPT% |
| 174 | goto END |
| 175 | :KARAF_PROFILER_END |
| 176 | |
| 177 | rem Setup the classpath |
| 178 | pushd "%KARAF_HOME%\lib" |
| 179 | for %%G in (*.*) do call:APPEND_TO_CLASSPATH %%G |
| 180 | popd |
| 181 | goto CLASSPATH_END |
| 182 | |
| 183 | : APPEND_TO_CLASSPATH |
| 184 | set filename=%~1 |
| 185 | set suffix=%filename:~-4% |
| 186 | if %suffix% equ .jar set CLASSPATH=%CLASSPATH%;%KARAF_HOME%\lib\%filename% |
| 187 | goto :EOF |
| 188 | |
| 189 | :CLASSPATH_END |
| 190 | |
| 191 | rem Execute the JVM or the load the profiler |
| 192 | if "%KARAF_PROFILER%" == "" goto :RUN |
| 193 | rem Execute the profiler if it has been configured |
| 194 | call :warn Loading profiler script: %KARAF_PROFILER_SCRIPT% |
| 195 | call %KARAF_PROFILER_SCRIPT% |
| 196 | |
| 197 | :RUN |
| 198 | SET OPTS=-Dkaraf.startLocalConsole=true -Dkaraf.startRemoteShell=true |
Guillaume Nodet | 774961d | 2010-04-30 09:28:30 +0000 | [diff] [blame] | 199 | SET MAIN=org.apache.felix.karaf.main.Main |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 200 | SET SHIFT=false |
Guillaume Nodet | 1da9ce1 | 2010-01-18 14:34:26 +0000 | [diff] [blame] | 201 | if "%1" == "stop" goto :EXECUTE_STOP |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 202 | if "%1" == "console" goto :EXECUTE_CONSOLE |
| 203 | if "%1" == "server" goto :EXECUTE_SERVER |
| 204 | if "%1" == "client" goto :EXECUTE_CLIENT |
| 205 | goto :EXECUTE |
| 206 | |
Guillaume Nodet | 1da9ce1 | 2010-01-18 14:34:26 +0000 | [diff] [blame] | 207 | :EXECUTE_STOP |
| 208 | SET MAIN=org.apache.felix.karaf.main.Stop |
| 209 | SET SHIFT=true |
| 210 | goto :EXECUTE |
| 211 | |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 212 | :EXECUTE_CONSOLE |
| 213 | SET SHIFT=true |
Guillaume Nodet | 11b422f | 2010-04-30 14:49:11 +0000 | [diff] [blame] | 214 | goto :EXECUTE |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 215 | |
| 216 | :EXECUTE_SERVER |
Guillaume Nodet | 9d8d3e1 | 2009-08-07 10:02:36 +0000 | [diff] [blame] | 217 | SET OPTS=-Dkaraf.startLocalConsole=false -Dkaraf.startRemoteShell=true |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 218 | SET SHIFT=true |
| 219 | goto :EXECUTE |
| 220 | |
| 221 | :EXECUTE_CLIENT |
Guillaume Nodet | 9d8d3e1 | 2009-08-07 10:02:36 +0000 | [diff] [blame] | 222 | SET OPTS=-Dkaraf.startLocalConsole=true -Dkaraf.startRemoteShell=false |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 223 | SET SHIFT=true |
| 224 | goto :EXECUTE |
| 225 | |
| 226 | :EXECUTE |
| 227 | if "%SHIFT%" == "true" SET ARGS=%2 %3 %4 %5 %6 %7 %8 |
Guillaume Nodet | 11b422f | 2010-04-30 14:49:11 +0000 | [diff] [blame] | 228 | if not "%SHIFT%" == "true" SET ARGS=%1 %2 %3 %4 %5 %6 %7 %8 |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 229 | rem Execute the Java Virtual Machine |
Guillaume Nodet | 11b422f | 2010-04-30 14:49:11 +0000 | [diff] [blame] | 230 | cd %KARAF_BASE% |
| 231 | "%JAVA%" %JAVA_OPTS% %OPTS% -classpath "%CLASSPATH%" -Djava.endorsed.dirs="%JAVA_HOME%\lib\endorsed;%KARAF_HOME%\lib\endorsed" -Djava.ext.dirs="%JAVA_HOME%\lib\ext;%KARAF_HOME%\lib\ext" -Dstorage.location="%KARAF_HOME%\instances" -Dkaraf.home="%KARAF_HOME%" -Dkaraf.base="%KARAF_BASE%" -Djava.util.logging.config.file="%KARAF_BASE%\etc\java.util.logging.properties" %MAIN% %ARGS% |
Chris Custine | ad72828 | 2009-05-04 06:11:07 +0000 | [diff] [blame] | 232 | |
| 233 | rem # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 234 | |
| 235 | :END |
| 236 | |
| 237 | endlocal |
| 238 | |
| 239 | if not "%PAUSE%" == "" pause |
| 240 | |
| 241 | :END_NO_PAUSE |
| 242 | |