Scratchpad

import java.io.*; import java.util.jar.*;

public class JarExtractor {

    public static void extractJar(String jarFilePath, String outputDirPath) throws IOException {
        // Ensure the output directory exists
        File outputDir = new File(outputDirPath);
        if (!outputDir.exists()) {
            outputDir.mkdirs();
        }

        // Open the JAR file
        try (JarFile jarFile = new JarFile(jarFilePath)) {
            // Iterate through JAR entries
            jarFile.stream().forEach(entry -> {
                if (!entry.isDirectory()) {
                    File outputFile = new File(outputDir, entry.getName());
                    try {
                        // Ensure parent directories exist
                        outputFile.getParentFile().mkdirs();

                        // Extract file content
                        try (InputStream inputStream = jarFile.getInputStream(entry);
                             OutputStream outputStream = new FileOutputStream(outputFile)) {
                            byte[] buffer = new byte[1024];
                            int bytesRead;
                            while ((bytesRead = inputStream.read(buffer)) != -1) {
                                outputStream.write(buffer, 0, bytesRead);
                            }
                        }
                    } catch (IOException e) {
                        System.err.println("Failed to extract: " + entry.getName());
                        e.printStackTrace();
                    }
                }
            });
        }
    }

    public static void main(String[] args) {
        if (args.length < 2) {
            System.out.println("Usage: java JarExtractor <jar-file-path> <output-dir