1@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. 39echo WARNING: Java not found in your path. 40 41rem The strategy is to look for Java under these 3 locations: 42rem - %ProgramFiles%, which may point to either a 32-bit or 64-bit install 43rem depending on the current invocation context 44rem - %ProgramW6432%, which points to a 32-bit install. This may not be defined. 45rem - %ProgramFiles(x86)%, which points to a 64-bit install. This may not be defined. 46 47if not defined ProgramFiles goto :Check64 48echo Checking if Java is installed in %ProgramFiles%\Java. 49 50set java_exe= 51for /D %%a in ( "%ProgramW6432%\Java\*" ) do call :TestJavaDir "%%a" 52if defined java_exe goto :EOF 53 54rem Check for the "default" 64-bit version if it's not the same path 55:Check64 56if not defined ProgramW6432 goto :Check32 57if "%ProgramW6432%"=="%ProgramFiles%" goto :Check32 58echo Checking if Java is installed in %ProgramW6432%\Java instead (64-bit). 59 60set java_exe= 61for /D %%a in ( "%ProgramW6432%\Java\*" ) do call :TestJavaDir "%%a" 62if defined java_exe goto :EOF 63 64rem Check for the "default" 32-bit version if it's not the same path 65:Check32 66if not defined ProgramFiles(x86) goto :CheckFailed 67if "%ProgramFiles(x86)%"=="%ProgramFiles%" goto :CheckFailed 68echo Checking if Java is installed in %ProgramFiles(x86)%\Java instead (32-bit). 69 70set java_exe= 71for /D %%a in ( "%ProgramFiles(x86)%\Java\*" ) do call :TestJavaDir "%%a" 72if defined java_exe goto :EOF 73 74:CheckFailed 75echo. 76echo ERROR: No suitable Java found. In order to properly use the Android Developer 77echo Tools, you need a suitable version of Java JDK installed on your system. 78echo We recommend that you install the JDK version of JavaSE, available here: 79echo http://www.oracle.com/technetwork/java/javase/downloads 80echo. 81echo You can find the complete Android SDK requirements here: 82echo http://developer.android.com/sdk/requirements.html 83echo. 84goto :EOF 85 86rem --------------- 87:TestJavaDir 88rem This is a "subrountine" for the for /D above. It tests the short version 89rem of the %1 path (i.e. the path with only short names and no spaces). 90rem However we use the full version without quotes (e.g. %~1) for pretty print. 91if defined java_exe goto :EOF 92set full_path=%~1\bin\java.exe 93set short_path=%~s1\bin\java.exe 94 95%short_path% -version 2>nul 96if ERRORLEVEL 1 goto :EOF 97set java_exe=%short_path% 98 99echo. 100echo Java was found at %full_path%. 101echo Please consider adding it to your path: 102echo - Under Windows XP, open Control Panel / System / Advanced / Environment Variables 103echo - Under Windows Vista or Windows 7, open Control Panel / System / Advanced System Settings / Environment Variables 104echo At the end of the "Path" entry in "User variables", add the following: 105echo ;%full_path% 106echo. 107