code: public static File unpack(File directory) {
          if (!directory.exists()) {
              if (!directory.mkdirs()) {
                  throw new IllegalArgumentException("Failed to make target directory: " + directory);
              }
          }
  
          File file;
          boolean chmodx;
          String osname = System.getProperty("os.name").toLowerCase();
          if (osname.contains("win")) {
              file = new File(directory, "phantomjs.exe");
              unpack("windows/phantomjs.exe", file);
              chmodx = false;
          } else if (osname.contains("mac os")) {
              file = new File(directory, "phantomjs");
              unpack("macosx/phantomjs", file);
              chmodx = true;
  
          } else if (osname.contains("linux")) {
              file = new File(directory, "phantomjs");
              //Linux has i386 or amd64
              String osarch = System.getProperty("os.arch");
              if (osarch.equals("i386")) {
                  unpack("linux86/phantomjs", file);
              } else {
                  unpack("linux64/phantomjs", file);
              }
              chmodx = true;
  
          } else {
              throw new IllegalArgumentException("Unsupported OS " + osname);
          }
  
          if (chmodx) {
              if (!file.setExecutable(true)) {
                  throw new IllegalArgumentException("Failed to make executable " + file);
              }
          }
  
          return file;
      }
docs: Unpack bundled phantomjs binary into specified directory
  
  @param directory
  @return File of the unbundled phantomjs binary