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