| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 1 | @echo off
|
| 2 | rem Copyright (C) 2007 The Android Open Source Project
|
| 3 | rem
|
| 4 | rem Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 | rem you may not use this file except in compliance with the License.
|
| 6 | rem You may obtain a copy of the License at
|
| 7 | rem
|
| 8 | rem http://www.apache.org/licenses/LICENSE-2.0
|
| 9 | rem
|
| 10 | rem Unless required by applicable law or agreed to in writing, software
|
| 11 | rem distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 | rem See the License for the specific language governing permissions and
|
| 14 | rem limitations under the License.
|
| 15 |
|
| 16 | rem This script is called by the other batch files to find a suitable Java.exe
|
| 17 | rem to use. The script changes the "java_exe" env variable. The variable
|
| 18 | rem is left unset if Java.exe was not found.
|
| 19 |
|
| 20 | rem Useful links:
|
| 21 | rem Command-line reference:
|
| 22 | rem http://technet.microsoft.com/en-us/library/bb490890.aspx
|
| 23 |
|
| 24 | rem Check we have a valid Java.exe in the path. The return code will
|
| 25 | rem be 0 if the command worked or 9009 if the exec failed (program not found).
|
| 26 | rem Java itself will return 1 if the argument is not understood.
|
| Raphael | 58fd507 | 2011-11-11 10:43:03 -0800 | [diff] [blame] | 27 | set java_exe=java.exe
|
| 28 | rem search it in the path and verify we can execute it
|
| 29 | for %%a in (%java_exe%) do set java_exe=%%~s$PATH:a
|
| 30 | if not exist %java_exe% goto SearchForJava
|
| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 31 | %java_exe% -version 2>nul
|
| 32 | if ERRORLEVEL 1 goto SearchForJava
|
| Raphael | 58fd507 | 2011-11-11 10:43:03 -0800 | [diff] [blame] | 33 | goto :SearchJavaW
|
| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 34 |
|
| 35 |
|
| 36 | rem ---------------
|
| 37 | :SearchForJava
|
| 38 | rem We get here if the default %java_exe% was not found in the path.
|
| 39 | rem Search for an alternative in %ProgramFiles%\Java\*\bin\java.exe
|
| 40 |
|
| 41 | echo.
|
| Raphael | ea66c92 | 2010-01-27 12:48:34 -0800 | [diff] [blame] | 42 | echo WARNING: Java not found in your path.
|
| Raphael Moll | a5dd865 | 2010-08-20 21:54:59 -0700 | [diff] [blame] | 43 |
|
| Raphael Moll | 11583cc | 2011-08-26 14:13:16 -0700 | [diff] [blame] | 44 | rem The strategy is to look for Java under these 3 locations:
|
| 45 | rem - %ProgramFiles%, which may point to either a 32-bit or 64-bit install
|
| 46 | rem depending on the current invocation context
|
| 47 | rem - %ProgramW6432%, which points to a 32-bit install. This may not be defined.
|
| 48 | rem - %ProgramFiles(x86)%, which points to a 64-bit install. This may not be defined.
|
| 49 |
|
| 50 | if not defined ProgramFiles goto :Check64
|
| 51 | echo Checking if Java is installed in %ProgramFiles%\Java.
|
| Raphael Moll | a5dd865 | 2010-08-20 21:54:59 -0700 | [diff] [blame] | 52 |
|
| 53 | set java_exe=
|
| 54 | for /D %%a in ( "%ProgramW6432%\Java\*" ) do call :TestJavaDir "%%a"
|
| Raphael | 58fd507 | 2011-11-11 10:43:03 -0800 | [diff] [blame] | 55 | if defined java_exe goto :SearchJavaW
|
| Raphael Moll | a5dd865 | 2010-08-20 21:54:59 -0700 | [diff] [blame] | 56 |
|
| Raphael Moll | 11583cc | 2011-08-26 14:13:16 -0700 | [diff] [blame] | 57 | rem Check for the "default" 64-bit version if it's not the same path
|
| 58 | :Check64
|
| 59 | if not defined ProgramW6432 goto :Check32
|
| 60 | if "%ProgramW6432%"=="%ProgramFiles%" goto :Check32
|
| 61 | echo Checking if Java is installed in %ProgramW6432%\Java instead (64-bit).
|
| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 62 |
|
| 63 | set java_exe=
|
| Raphael Moll | 11583cc | 2011-08-26 14:13:16 -0700 | [diff] [blame] | 64 | for /D %%a in ( "%ProgramW6432%\Java\*" ) do call :TestJavaDir "%%a"
|
| Raphael | 58fd507 | 2011-11-11 10:43:03 -0800 | [diff] [blame] | 65 | if defined java_exe goto :SearchJavaW
|
| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 66 |
|
| Raphael Moll | 11583cc | 2011-08-26 14:13:16 -0700 | [diff] [blame] | 67 | rem Check for the "default" 32-bit version if it's not the same path
|
| 68 | :Check32
|
| 69 | if not defined ProgramFiles(x86) goto :CheckFailed
|
| 70 | if "%ProgramFiles(x86)%"=="%ProgramFiles%" goto :CheckFailed
|
| 71 | echo Checking if Java is installed in %ProgramFiles(x86)%\Java instead (32-bit).
|
| 72 |
|
| 73 | set java_exe=
|
| 74 | for /D %%a in ( "%ProgramFiles(x86)%\Java\*" ) do call :TestJavaDir "%%a"
|
| Raphael | 58fd507 | 2011-11-11 10:43:03 -0800 | [diff] [blame] | 75 | if defined java_exe goto :SearchJavaW
|
| Raphael Moll | 11583cc | 2011-08-26 14:13:16 -0700 | [diff] [blame] | 76 |
|
| 77 | :CheckFailed
|
| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 78 | echo.
|
| Raphael | ea66c92 | 2010-01-27 12:48:34 -0800 | [diff] [blame] | 79 | echo ERROR: No suitable Java found. In order to properly use the Android Developer
|
| Raphael Moll | a5dd865 | 2010-08-20 21:54:59 -0700 | [diff] [blame] | 80 | echo Tools, you need a suitable version of Java JDK installed on your system.
|
| 81 | echo We recommend that you install the JDK version of JavaSE, available here:
|
| 82 | echo http://www.oracle.com/technetwork/java/javase/downloads
|
| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 83 | echo.
|
| 84 | echo You can find the complete Android SDK requirements here:
|
| 85 | echo http://developer.android.com/sdk/requirements.html
|
| 86 | echo.
|
| 87 | goto :EOF
|
| 88 |
|
| 89 | rem ---------------
|
| 90 | :TestJavaDir
|
| 91 | rem This is a "subrountine" for the for /D above. It tests the short version
|
| 92 | rem of the %1 path (i.e. the path with only short names and no spaces).
|
| 93 | rem However we use the full version without quotes (e.g. %~1) for pretty print.
|
| 94 | if defined java_exe goto :EOF
|
| 95 | set full_path=%~1\bin\java.exe
|
| 96 | set short_path=%~s1\bin\java.exe
|
| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 97 |
|
| 98 | %short_path% -version 2>nul
|
| 99 | if ERRORLEVEL 1 goto :EOF
|
| 100 | set java_exe=%short_path%
|
| 101 |
|
| 102 | echo.
|
| 103 | echo Java was found at %full_path%.
|
| 104 | echo Please consider adding it to your path:
|
| 105 | echo - Under Windows XP, open Control Panel / System / Advanced / Environment Variables
|
| Raphael Moll | a5dd865 | 2010-08-20 21:54:59 -0700 | [diff] [blame] | 106 | echo - Under Windows Vista or Windows 7, open Control Panel / System / Advanced System Settings / Environment Variables
|
| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 107 | echo At the end of the "Path" entry in "User variables", add the following:
|
| 108 | echo ;%full_path%
|
| 109 | echo.
|
| Raphael | 58fd507 | 2011-11-11 10:43:03 -0800 | [diff] [blame] | 110 | goto :EOF
|
| 111 |
|
| 112 | rem ---------------
|
| 113 | :SearchJavaW
|
| 114 | rem Called once java_exe has been set. Try to see if we can find a javaw
|
| 115 | rem to use. If not, we'll default to using java_exe.
|
| 116 | for %%a in (%java_exe%) do set p=%%~pa
|
| 117 | for %%a in (%java_exe%) do set n=%%~na
|
| 118 | for %%a in (%java_exe%) do set x=%%~xa
|
| 119 | set n=%n:java=javaw%
|
| 120 | set javaw_exe=%p%%n%%x%
|
| 121 | if not exist %javaw_exe% set javaw_exe=%java_exe%
|
| 122 | goto :EOF
|