| 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.
|
| 27 | set java_exe=java
|
| 28 | %java_exe% -version 2>nul
|
| 29 | if ERRORLEVEL 1 goto SearchForJava
|
| 30 | goto :EOF
|
| 31 |
|
| 32 |
|
| 33 | rem ---------------
|
| 34 | :SearchForJava
|
| 35 | rem We get here if the default %java_exe% was not found in the path.
|
| 36 | rem Search for an alternative in %ProgramFiles%\Java\*\bin\java.exe
|
| 37 |
|
| 38 | echo.
|
| Raphael | ea66c92 | 2010-01-27 12:48:34 -0800 | [diff] [blame] | 39 | echo WARNING: Java not found in your path.
|
| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 40 | echo Checking it it's installed in %ProgramFiles%\Java instead.
|
| 41 | echo.
|
| 42 |
|
| 43 | set java_exe=
|
| 44 | for /D %%a in ( "%ProgramFiles%\Java\*" ) do call :TestJavaDir "%%a"
|
| 45 | if defined java_exe goto :EOF
|
| 46 |
|
| 47 | echo.
|
| Raphael | ea66c92 | 2010-01-27 12:48:34 -0800 | [diff] [blame] | 48 | echo ERROR: No suitable Java found. In order to properly use the Android Developer
|
| 49 | echo Tools, you need a suitable version of Java installed on your system. We
|
| 50 | echo recommend that you install the JDK version of JavaSE, available here:
|
| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 51 | echo http://java.sun.com/javase/downloads/
|
| 52 | echo.
|
| 53 | echo You can find the complete Android SDK requirements here:
|
| 54 | echo http://developer.android.com/sdk/requirements.html
|
| 55 | echo.
|
| 56 | goto :EOF
|
| 57 |
|
| 58 | rem ---------------
|
| 59 | :TestJavaDir
|
| 60 | rem This is a "subrountine" for the for /D above. It tests the short version
|
| 61 | rem of the %1 path (i.e. the path with only short names and no spaces).
|
| 62 | rem However we use the full version without quotes (e.g. %~1) for pretty print.
|
| 63 | if defined java_exe goto :EOF
|
| 64 | set full_path=%~1\bin\java.exe
|
| 65 | set short_path=%~s1\bin\java.exe
|
| 66 | rem [for debugging] echo Testing %full_path%
|
| 67 |
|
| 68 | %short_path% -version 2>nul
|
| 69 | if ERRORLEVEL 1 goto :EOF
|
| 70 | set java_exe=%short_path%
|
| 71 |
|
| 72 | echo.
|
| 73 | echo Java was found at %full_path%.
|
| 74 | echo Please consider adding it to your path:
|
| 75 | echo - Under Windows XP, open Control Panel / System / Advanced / Environment Variables
|
| 76 | echo - Under Windows Vista, open Control Panel / System / Advanced System Settings
|
| Raphael | ea66c92 | 2010-01-27 12:48:34 -0800 | [diff] [blame] | 77 | echo / Environment Variables
|
| Raphael | 047e5f5 | 2010-01-26 16:08:17 -0800 | [diff] [blame] | 78 | echo At the end of the "Path" entry in "User variables", add the following:
|
| 79 | echo ;%full_path%
|
| 80 | echo.
|