Is there any way i can read the contents of a jar file. like i want to read the manifest file in order to find the creator of the jar file and version. Is there any way to a
public void processManifestFile() {
String version = this.getClass().getPackage().getImplementationVersion();
LOG.info("Version: {}", version);
Path targetFile = Paths.get(System.getProperty("user.home"), "my-project", "MANIFEST.MF");
try {
URL url = this.getClass().getProtectionDomain().getCodeSource().getLocation();
JarFile jarFile = new JarFile(url.getFile());
Manifest manifest = jarFile.getManifest();
try(FileWriter fw = new FileWriter(targetFile.toFile())) {
manifest.getMainAttributes().entrySet().stream().forEach( x -> {
try {
fw.write(x.getKey() + ": " + x.getValue() + "\n");
LOG.info("{}: {}", x.getKey(), x.getValue());
} catch (IOException e) {
LOG.error("error in write manifest, {}", e.getMessage());
}
});
}
LOG.info("Copy MANIFEST.MF to {}", targetFile);
} catch (Exception e) {
LOG.error("Error in processing MANIFEST.MF file", e);
}
}