private static Optional<File> findExecutableOnSystemPath(final String executableName) {
    for (final String pathPath : Splitter.on(File.pathSeparator).split(System.getenv("PATH"))) {
      final File probeFile = new File(pathPath, executableName);
      if (probeFile.isFile() && java.nio.file.Files.isExecutable(probeFile.toPath())) {
        return Optional.of(probeFile);
      }
    }
    return Optional.absent();
  }
private static Optional < File > findExecutableOnSystemPath ( final String executableName ) { for ( final String pathPath : Splitter . on ( File . pathSeparator ) . split ( System . getenv ( "PATH" ) ) ) { final File probeFile = new File ( pathPath , executableName ) ; if ( probeFile . isFile ( ) && java . nio . file . Files . isExecutable ( probeFile . toPath ( ) ) ) { return Optional . of ( probeFile ) ; } } return Optional . absent ( ) ; }
warning: this will fail if the user has an escape path separator in a path