xref: /aosp_15_r20/sdk/find_java/find_java.bat (revision 1789df15502f1991eff51ff970dce5df8404dd56)
1*1789df15SXin Li@echo off
2*1789df15SXin Lirem Copyright (C) 2007 The Android Open Source Project
3*1789df15SXin Lirem
4*1789df15SXin Lirem Licensed under the Apache License, Version 2.0 (the "License");
5*1789df15SXin Lirem you may not use this file except in compliance with the License.
6*1789df15SXin Lirem You may obtain a copy of the License at
7*1789df15SXin Lirem
8*1789df15SXin Lirem      http://www.apache.org/licenses/LICENSE-2.0
9*1789df15SXin Lirem
10*1789df15SXin Lirem Unless required by applicable law or agreed to in writing, software
11*1789df15SXin Lirem distributed under the License is distributed on an "AS IS" BASIS,
12*1789df15SXin Lirem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*1789df15SXin Lirem See the License for the specific language governing permissions and
14*1789df15SXin Lirem limitations under the License.
15*1789df15SXin Li
16*1789df15SXin Lirem This script is called by the other batch files to find a suitable Java.exe
17*1789df15SXin Lirem to use. The script changes the "java_exe" env variable. The variable
18*1789df15SXin Lirem is left unset if Java.exe was not found.
19*1789df15SXin Li
20*1789df15SXin Lirem Useful links:
21*1789df15SXin Lirem Command-line reference:
22*1789df15SXin Lirem   http://technet.microsoft.com/en-us/library/bb490890.aspx
23*1789df15SXin Li
24*1789df15SXin Lirem Query whether this system is 32-bit or 64-bit
25*1789df15SXin Lirem Note: Some users report that reg.exe is missing on their machine, so we
26*1789df15SXin Lirem check for that first, as we'd like to use it if we can.
27*1789df15SXin Liset sys_32=%SYSTEMROOT%\system32
28*1789df15SXin Liif exist %sys_32%\reg.exe (
29*1789df15SXin Li    rem This first-pass solution returns the correct architecture even if you
30*1789df15SXin Li    rem call this .bat file from a 32-bit process.
31*1789df15SXin Li    rem See also: http://stackoverflow.com/a/24590583/1299302
32*1789df15SXin Li    %sys_32%\reg query "HKLM\Hardware\Description\System\CentralProcessor\0"^
33*1789df15SXin Li    | %sys_32%\find /i "x86" > NUL && set arch_ext=32|| set arch_ext=64
34*1789df15SXin Li) else (
35*1789df15SXin Li    rem This fallback approach is simpler, but may misreport your architecture as
36*1789df15SXin Li    rem 32-bit if running from a 32-bit process. Still, it should serve to help
37*1789df15SXin Li    rem our users without reg.exe, at least.
38*1789df15SXin Li    if "%PROCESSOR_ARCHITECTURE%" == "x86" (set arch_ext=32) else (set arch_ext=64)
39*1789df15SXin Li)
40*1789df15SXin Li
41*1789df15SXin Lirem Check we have a valid Java.exe in the path. The return code will
42*1789df15SXin Lirem be 0 if the command worked or 1 if the exec failed (program not found).
43*1789df15SXin Lifor /f "delims=" %%a in ('"%~dps0\find_java%arch_ext%.exe" -s') do set java_exe=%%a
44*1789df15SXin Liif not defined java_exe goto :CheckFailed
45*1789df15SXin Li
46*1789df15SXin Li:SearchJavaW
47*1789df15SXin Lirem Check if we can find a javaw.exe at the same location than java.exe.
48*1789df15SXin Lirem If that doesn't work, just fall back on the java.exe we just found.
49*1789df15SXin Lifor /f "delims=" %%a in ('"%~dps0\find_java%arch_ext%.exe" -s -w') do set javaw_exe=%%a
50*1789df15SXin Liif not exist "%javaw_exe%" set javaw_exe=%java_exe%
51*1789df15SXin Ligoto :EOF
52*1789df15SXin Li
53*1789df15SXin Li
54*1789df15SXin Li:CheckFailed
55*1789df15SXin Liecho.
56*1789df15SXin Liecho ERROR: No suitable Java found. In order to properly use the Android Developer
57*1789df15SXin Liecho Tools, you need a suitable version of Java JDK installed on your system.
58*1789df15SXin Liecho We recommend that you install the JDK version of JavaSE, available here:
59*1789df15SXin Liecho   http://www.oracle.com/technetwork/java/javase/downloads
60*1789df15SXin Liecho.
61*1789df15SXin Liecho If you already have Java installed, you can define the JAVA_HOME environment
62*1789df15SXin Liecho variable in Control Panel / System / Avanced System Settings to point to the
63*1789df15SXin Liecho JDK folder.
64*1789df15SXin Liecho.
65*1789df15SXin Liecho You can find the complete Android SDK requirements here:
66*1789df15SXin Liecho   http://developer.android.com/sdk/requirements.html
67*1789df15SXin Liecho.
68*1789df15SXin Ligoto :EOF
69