1

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Manitoba
  • 8,522
  • 11
  • 60
  • 122

1 Answers1

0

Finally, I found a way to make it.

I saved my file MANIFEST.MF into my main jar and used that code to replace the input.getManifest()

Manifest mf = new Manifest();
mf.read(getClass().getResourceAsStream("/lib/manifest.mf"));

In this case, I extracted the manifest.mf from obfuscated_jar.jar and 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.

Manitoba
  • 8,522
  • 11
  • 60
  • 122