Java File Attribute javaExecutable(File jre)

Here you can find the source of javaExecutable(File jre)

Description

java Executable

License

Open Source License

Parameter

Parameter Description
jre A valid JRE directory

Return

null if the java executable was not find, or a file object pointing to the executable

Declaration

public static File javaExecutable(File jre) 

Method Source Code

//package com.java2s;
/* Copyright (c) 2013-2014 Jesper ?qvist <jesper@llbit.se>
 *
 * This file is part of Chunky./*from w  ww  .  j  a  v  a 2s  .com*/
 *
 * Chunky is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Chunky is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Chunky.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

public class Main {
    /**
     * @param jre A valid JRE directory
     * @return {@code null} if the java executable was not find, or a
     * file object pointing to the executable
     */
    public static File javaExecutable(File jre) {
        if (!jre.isDirectory()) {
            return null;
        }
        File bin = new File(jre, "bin");
        if (bin != null && bin.isDirectory()) {
            String os = System.getProperty("os.name").toLowerCase();
            String exeName = os.contains("win") ? "java.exe" : "java";
            return new File(bin, exeName);
        }
        return null;
    }
}

Related

  1. fileExecute(String path)
  2. findInPath(String executable, String path, String pathSeparator)
  3. findJavaCompilerExecutableInDir(File dir)
  4. findJavaExecutable(File vmInstallLocation)
  5. findUnixExecutable(String unixCommandLineExecutables)
  6. launchExecutable(String executable, List args, Preferences preferences)
  7. makeCurrentDirectoryThatOfExecutable(String executable)
  8. makeExecutable(File file)
  9. makeExecutable(File file)