Java JDK Home Get getJdkHome()

Here you can find the source of getJdkHome()

Description

Return a lazy guess at the JDK home based on the JAVA_HOME.

License

Apache License

Return

the JDK home or null if it can't be found

Declaration

private static File getJdkHome() 

Method Source Code

//package com.java2s;
/*/*from ww w .j a v a  2  s  .c  om*/
 * Copyright 2013 Ray Holder
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Override this system property if you want to change the JAVA_HOME for only the Gradle View plugin.
     */
    public static final String GRADLE_VIEW_JAVA_HOME_KEY = "gradle.view.java.home";

    /**
     * Return a lazy guess at the JDK home based on the JAVA_HOME.
     *
     * @return the JDK home or null if it can't be found
     */
    private static File getJdkHome() {
        List<String> candidates = new ArrayList<String>();

        // read from system property
        candidates.add(System.getProperty(GRADLE_VIEW_JAVA_HOME_KEY));

        // read from JAVA_HOME environment variable
        candidates.add(System.getenv("JAVA_HOME"));
        for (String candidate : candidates) {
            if (candidate != null) {
                File jdkHome = new File(candidate);
                if (jdkHome.exists()) {
                    return jdkHome;
                }
            }
        }
        return null;
    }
}

Related

  1. getJdkBin()
  2. getJdkHome()
  3. getJDKHomeVariable()
  4. getJDKPath(File file)