extractJar static method

Future<bool> extractJar(
  1. String jarPath,
  2. String extractDir
)

Extracts a JAR file to the specified directory

jarPath - Path to the JAR file extractDir - Directory where the JAR contents will be extracted Returns true if extraction was successful, false otherwise

Implementation

static Future<bool> extractJar(String jarPath, String extractDir) async {
  try {
    final dir = Directory(extractDir);
    if (!await dir.exists()) {
      await dir.create(recursive: true);
    }

    final process = await Process.run('jar', [
      'xf',
      jarPath,
    ], workingDirectory: extractDir);

    if (process.exitCode != 0) {
      final javaProcess = await Process.run('java', [
        '-jar',
        '-xf',
        jarPath,
      ], workingDirectory: extractDir);

      if (javaProcess.exitCode != 0) {
        return await _extractJarAsZip(jarPath, extractDir);
      }
    }

    return true;
  } catch (e) {
    return await _extractJarAsZip(jarPath, extractDir);
  }
}