public static void unjar(Path file, Path to) throws IOException {
    if (Files.notExists(to)) {
      Files.createDirectories(to);
    }

    try (JarFile jarFile = new JarFile(file.toFile())) {
      Enumeration<JarEntry> entries = jarFile.entries();
      while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        Path entryPath = to.resolve(entry.getName());
        if (!entry.isDirectory()) {
          if (Files.notExists(entryPath.getParent())) {
            Files.createDirectories(entryPath.getParent());
          }

          if (Files.isRegularFile(entryPath)) {
            if (Files.size(entryPath) == entry.getSize()) {
              continue;
            } else {
              Files.delete(entryPath);
            }
          }

          Files.createFile(entryPath);

          try (OutputStream os = Files.newOutputStream(entryPath)) {
            InputStream is = jarFile.getInputStream(entry);
            byte[] ba = new byte[1024];
            int read;
            while ((read = is.read(ba)) != -1) {
              if (read > 0) {
                os.write(ba, 0, read);
              }
            }
          }
        }
      }
    }
  }