I want to generate programtically a jar file in java. This works well when the input jar file has NOT been obfuscated. When I use an obfuscator on it, the first entry is no longer the manifest, so I can’t generate a new file…
Here is my code:
JarInputStream input = new JarInputStream(getClass().getResourceAsStream("/obfuscated_jar.jar"));
JarOutputStream output = new JarOutputStream(new FileOutputStream("generated_jar.jar"), input.getManifest());
The line input.getManifest() returns null because the manifest is not at the first place.
I’ve made some searches on it, and it looks to be a known issue with JarInputStream. So here is my question: Is it possible to solve it? Like writing my own getManifest method or something?
Finally, I found a way to make it.
I saved my file
MANIFEST.MFinto my main jar and used that code to replace theinput.getManifest()In this case, I extracted the
manifest.mffromobfuscated_jar.jarand paste it into the lib folder of my main jar file.That’s probably not the best way but it works!
I hope this could help someone.