2 Ekim 2018 Salı

JarOutputStream Sınıfı - Jar Dosyası Yaratır

Giriş
Şu satırı dahil ederiz
import java.util.jar.JarOutputStream;
constructor
Örnek
Şöyle yaparız
public static void createJarFile(String sourceDir, List<String> files, String outputJar) {
  try (FileOutputStream out = new FileOutputStream(outputJar);
    JarOutputStream jarOS = new JarOutputStream(out)) {

    for (String file : files) {
      writeEntry(jarOS, sourceDir, file);
    }
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

private static void writeEntry(JarOutputStream jarOS, String sourceFolder, String name)
throws IOException {
  jarOS.putNextEntry(new JarEntry(name));
  try (FileInputStream fis = new FileInputStream(sourceFolder + name)) {
    jarOS.write(IOUtils.toByteArray(fis));
  }
  jarOS.closeEntry();
}
constructor
Şöyle yaparız.
Manifest manifest = ...
JarOutputStream target = new JarOutputStream(new FileOutputStream("output.jar"),manifest);

Hiç yorum yok:

Yorum Gönder