0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License, Version 1.0 only
0N/A * (the "License"). You may not use this file except in compliance
0N/A * with the License.
0N/A *
6983N/A * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
6983N/A * or http://forgerock.org/license/CDDLv1.0.html.
0N/A * See the License for the specific language governing permissions
0N/A * and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
6983N/A * file and include the License file at legal-notices/CDDLv1_0.txt.
6983N/A * If applicable, add the following below this CDDL HEADER, with the
6983N/A * fields enclosed by brackets "[]" replaced with your own identifying
6983N/A * information:
0N/A * Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A *
0N/A *
3233N/A * Copyright 2006-2008 Sun Microsystems, Inc.
0N/A */
0N/Aimport java.io.*;
0N/A
0N/A
0N/A
0N/A/**
0N/A * This program provides a simple utility that determines the location of the
0N/A * Java installation. The output will be in a form suitable for use in a
0N/A * JAVA_HOME environment variable.
0N/A */
0N/Apublic class FindJavaHome
0N/A{
0N/A public static void main(String[] args)
0N/A throws Exception
0N/A {
0N/A String javaHome = System.getProperty("java.home");
0N/A File javaHomeDir = new File(javaHome);
0N/A if (! javaHomeDir.exists())
0N/A {
0N/A throw new Exception("System property java.home doesn't reference a " +
0N/A "real directory");
0N/A }
0N/A
0N/A String javacPath = File.separator + "bin" + File.separator + "javac";
0N/A File javacFile = new File(javaHome + javacPath);
0N/A if (! javacFile.exists())
0N/A {
0N/A javacFile = new File(javaHomeDir.getParent() + javacPath);
0N/A if (javacFile.exists())
0N/A {
0N/A javaHomeDir = new File(javaHomeDir.getParent());
0N/A }
0N/A else
0N/A {
0N/A throw new Exception("Unable to determine Java compiler location " +
0N/A "from java.home property value " + javaHome);
0N/A }
0N/A }
0N/A
0N/A System.out.println(javaHomeDir.getAbsolutePath());
0N/A }
0N/A}
0N/A