blob: ac11d0678ef1d737dafccd2eee15484e73f42ef6 [file] [log] [blame]
Raphael047e5f52010-01-26 16:08:17 -08001@echo off
2rem Copyright (C) 2007 The Android Open Source Project
3rem
4rem Licensed under the Apache License, Version 2.0 (the "License");
5rem you may not use this file except in compliance with the License.
6rem You may obtain a copy of the License at
7rem
8rem http://www.apache.org/licenses/LICENSE-2.0
9rem
10rem Unless required by applicable law or agreed to in writing, software
11rem distributed under the License is distributed on an "AS IS" BASIS,
12rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13rem See the License for the specific language governing permissions and
14rem limitations under the License.
15
16rem This script is called by the other batch files to find a suitable Java.exe
17rem to use. The script changes the "java_exe" env variable. The variable
18rem is left unset if Java.exe was not found.
19
20rem Useful links:
21rem Command-line reference:
22rem http://technet.microsoft.com/en-us/library/bb490890.aspx
23
24rem Check we have a valid Java.exe in the path. The return code will
25rem be 0 if the command worked or 9009 if the exec failed (program not found).
26rem Java itself will return 1 if the argument is not understood.
27set java_exe=java
28%java_exe% -version 2>nul
29if ERRORLEVEL 1 goto SearchForJava
30goto :EOF
31
32
33rem ---------------
34:SearchForJava
35rem We get here if the default %java_exe% was not found in the path.
36rem Search for an alternative in %ProgramFiles%\Java\*\bin\java.exe
37
38echo.
Raphaelea66c922010-01-27 12:48:34 -080039echo WARNING: Java not found in your path.
Raphael047e5f52010-01-26 16:08:17 -080040echo Checking it it's installed in %ProgramFiles%\Java instead.
41echo.
42
43set java_exe=
44for /D %%a in ( "%ProgramFiles%\Java\*" ) do call :TestJavaDir "%%a"
45if defined java_exe goto :EOF
46
47echo.
Raphaelea66c922010-01-27 12:48:34 -080048echo ERROR: No suitable Java found. In order to properly use the Android Developer
49echo Tools, you need a suitable version of Java installed on your system. We
50echo recommend that you install the JDK version of JavaSE, available here:
Raphael047e5f52010-01-26 16:08:17 -080051echo http://java.sun.com/javase/downloads/
52echo.
53echo You can find the complete Android SDK requirements here:
54echo http://developer.android.com/sdk/requirements.html
55echo.
56goto :EOF
57
58rem ---------------
59:TestJavaDir
60rem This is a "subrountine" for the for /D above. It tests the short version
61rem of the %1 path (i.e. the path with only short names and no spaces).
62rem However we use the full version without quotes (e.g. %~1) for pretty print.
63if defined java_exe goto :EOF
64set full_path=%~1\bin\java.exe
65set short_path=%~s1\bin\java.exe
66rem [for debugging] echo Testing %full_path%
67
68%short_path% -version 2>nul
69if ERRORLEVEL 1 goto :EOF
70set java_exe=%short_path%
71
72echo.
73echo Java was found at %full_path%.
74echo Please consider adding it to your path:
75echo - Under Windows XP, open Control Panel / System / Advanced / Environment Variables
76echo - Under Windows Vista, open Control Panel / System / Advanced System Settings
Raphaelea66c922010-01-27 12:48:34 -080077echo / Environment Variables
Raphael047e5f52010-01-26 16:08:17 -080078echo At the end of the "Path" entry in "User variables", add the following:
79echo ;%full_path%
80echo.