blob: 298c1e69c31b744da23169b638151b8be638a74d [file] [log] [blame]
Chris Custinead728282009-05-04 06:11:07 +00001@echo off
2rem
3rem
4rem Licensed to the Apache Software Foundation (ASF) under one or more
5rem contributor license agreements. See the NOTICE file distributed with
6rem this work for additional information regarding copyright ownership.
7rem The ASF licenses this file to You under the Apache License, Version 2.0
8rem (the "License"); you may not use this file except in compliance with
9rem the License. You may obtain a copy of the License at
10rem
11rem http://www.apache.org/licenses/LICENSE-2.0
12rem
13rem Unless required by applicable law or agreed to in writing, software
14rem distributed under the License is distributed on an "AS IS" BASIS,
15rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16rem See the License for the specific language governing permissions and
17rem limitations under the License.
18rem
Guillaume Nodet11b422f2010-04-30 14:49:11 +000019rem
Guillaume Nodet874ecc82009-05-04 07:56:47 +000020rem $Id: karaf.bat 979 2005-11-30 22:50:55Z bsnyder $
Guillaume Nodet11b422f2010-04-30 14:49:11 +000021rem
Chris Custinead728282009-05-04 06:11:07 +000022
23if not "%ECHO%" == "" echo %ECHO%
24
25setlocal
26set DIRNAME=%~dp0%
27set PROGNAME=%~nx0%
28set ARGS=%*
29
30title Karaf
31
32goto BEGIN
33
34:warn
35 echo %PROGNAME%: %*
36goto :EOF
37
38:BEGIN
39
40rem # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
41
42if not "%KARAF_HOME%" == "" (
43 call :warn Ignoring predefined value for KARAF_HOME
44)
45set KARAF_HOME=%DIRNAME%..
46if not exist "%KARAF_HOME%" (
47 call :warn KARAF_HOME is not valid: %KARAF_HOME%
48 goto END
49)
50
51if not "%KARAF_BASE%" == "" (
52 if not exist "%KARAF_BASE%" (
53 call :warn KARAF_BASE is not valid: %KARAF_BASE%
54 goto END
55 )
56)
57if "%KARAF_BASE%" == "" (
58 set KARAF_BASE=%KARAF_HOME%
59)
60
61set LOCAL_CLASSPATH=%CLASSPATH%
62set DEFAULT_JAVA_OPTS=-server -Xmx512M -Dderby.system.home="%KARAF_BASE%\data\derby" -Dderby.storage.fileSyncTransactionLog=true -Dcom.sun.management.jmxremote
63set CLASSPATH=%LOCAL_CLASSPATH%;%KARAF_BASE%\conf
64set DEFAULT_JAVA_DEBUG_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
65
66if "%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
73rem Setup Karaf Home
74if exist "%KARAF_HOME%\conf\karaf-rc.cmd" call %KARAF_HOME%\conf\karaf-rc.cmd
75if exist "%HOME%\karaf-rc.cmd" call %HOME%\karaf-rc.cmd
76
77rem Support for loading native libraries
78set PATH=%PATH%;%KARAF_BASE%\lib;%KARAF_HOME%\lib
79
80rem Setup the Java Virtual Machine
81if not "%JAVA%" == "" goto :Check_JAVA_END
Guillaume Nodet11b422f2010-04-30 14:49:11 +000082 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 Custinead728282009-05-04 06:11:07 +0000152 if not exist "%JAVA_HOME%" (
153 call :warn JAVA_HOME is not valid: "%JAVA_HOME%"
154 goto END
155 )
Guillaume Nodet11b422f2010-04-30 14:49:11 +0000156 set JAVA=%JAVA_HOME%\bin\java
Chris Custinead728282009-05-04 06:11:07 +0000157:Check_JAVA_END
158
159if "%JAVA_OPTS%" == "" set JAVA_OPTS=%DEFAULT_JAVA_OPTS%
160
161if "%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 Nodet11b422f2010-04-30 14:49:11 +0000164
Chris Custinead728282009-05-04 06:11:07 +0000165 set "JAVA_OPTS=%JAVA_DEBUG_OPTS% %JAVA_OPTS%"
166 call :warn Enabling Java debug options: %JAVA_DEBUG_OPTS%
167:KARAF_DEBUG_END
168
169if "%KARAF_PROFILER%" == "" goto :KARAF_PROFILER_END
170 set KARAF_PROFILER_SCRIPT=%KARAF_HOME%\conf\profiler\%KARAF_PROFILER%.cmd
Guillaume Nodet11b422f2010-04-30 14:49:11 +0000171
Chris Custinead728282009-05-04 06:11:07 +0000172 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
177rem Setup the classpath
178pushd "%KARAF_HOME%\lib"
179for %%G in (*.*) do call:APPEND_TO_CLASSPATH %%G
180popd
181goto CLASSPATH_END
182
183: APPEND_TO_CLASSPATH
184set filename=%~1
185set suffix=%filename:~-4%
186if %suffix% equ .jar set CLASSPATH=%CLASSPATH%;%KARAF_HOME%\lib\%filename%
187goto :EOF
188
189:CLASSPATH_END
190
191rem Execute the JVM or the load the profiler
192if "%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 Nodet774961d2010-04-30 09:28:30 +0000199 SET MAIN=org.apache.felix.karaf.main.Main
Chris Custinead728282009-05-04 06:11:07 +0000200 SET SHIFT=false
Guillaume Nodet1da9ce12010-01-18 14:34:26 +0000201 if "%1" == "stop" goto :EXECUTE_STOP
Chris Custinead728282009-05-04 06:11:07 +0000202 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 Nodet1da9ce12010-01-18 14:34:26 +0000207:EXECUTE_STOP
208 SET MAIN=org.apache.felix.karaf.main.Stop
209 SET SHIFT=true
210 goto :EXECUTE
211
Chris Custinead728282009-05-04 06:11:07 +0000212:EXECUTE_CONSOLE
213 SET SHIFT=true
Guillaume Nodet11b422f2010-04-30 14:49:11 +0000214 goto :EXECUTE
Chris Custinead728282009-05-04 06:11:07 +0000215
216:EXECUTE_SERVER
Guillaume Nodet9d8d3e12009-08-07 10:02:36 +0000217 SET OPTS=-Dkaraf.startLocalConsole=false -Dkaraf.startRemoteShell=true
Chris Custinead728282009-05-04 06:11:07 +0000218 SET SHIFT=true
219 goto :EXECUTE
220
221:EXECUTE_CLIENT
Guillaume Nodet9d8d3e12009-08-07 10:02:36 +0000222 SET OPTS=-Dkaraf.startLocalConsole=true -Dkaraf.startRemoteShell=false
Chris Custinead728282009-05-04 06:11:07 +0000223 SET SHIFT=true
224 goto :EXECUTE
225
226:EXECUTE
227 if "%SHIFT%" == "true" SET ARGS=%2 %3 %4 %5 %6 %7 %8
Guillaume Nodet11b422f2010-04-30 14:49:11 +0000228 if not "%SHIFT%" == "true" SET ARGS=%1 %2 %3 %4 %5 %6 %7 %8
Chris Custinead728282009-05-04 06:11:07 +0000229 rem Execute the Java Virtual Machine
Guillaume Nodet11b422f2010-04-30 14:49:11 +0000230 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 Custinead728282009-05-04 06:11:07 +0000232
233rem # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
234
235:END
236
237endlocal
238
239if not "%PAUSE%" == "" pause
240
241:END_NO_PAUSE
242