Example #1
0
  /**
   * Gets the java home folder through the process ID of this process.
   *
   * @return The path to the java folder
   * @throws CLIException Reporting a failure to retrieve the java home directory
   */
  private String getJavaHomeDirectory() throws CLIException {
    try {
      final Sigar sigar = SigarHolder.getSigar();
      final long thisProcessPid = sigar.getPid();
      // get the java path of the current running process.
      final String javaFilePath = sigar.getProcExe(thisProcessPid).getName();
      final File javaFile = new File(javaFilePath);

      // Locate the java folder.
      final File javaFolder = javaFile.getParentFile().getParentFile();
      final String javaFolderPath = javaFolder.getAbsolutePath();
      return javaFolderPath;
    } catch (final SigarException e) {
      throw new CLIException("Failed to set the JAVA_HOME environment variable.", e);
    }
  }