1

When I upload a jar file to a servlet and try reading its manifest. jarStream.getManifest() returns null..

JarInputStream jarInputStream = new JarInputStream(inputStream);

Manifest mf = jarInputStream.getManifest();

While the same jar when I read as JarFile providing an absolute path, I get the manifest of the jar..

I need to read the manifest of the jar file at runtime.. when it is uploaded..

Any suggestions are most appreciated..

Komal Goyal
  • 233
  • 5
  • 17
  • It's a bug or poorly documented feature of `JarInputStream`, see answer https://stackoverflow.com/a/70363276/1795426 and also [JDK-8031748](https://bugs.openjdk.java.net/browse/JDK-8031748) – user11153 Dec 15 '21 at 12:04

2 Answers2

1

By packaging the jar using ant script to provide the custom attributes to the manifest helped to get the manifest successfully.

previously I was packaging the jar using eclipse>export>java>java archive where the manifest was default, editing the manifest of this exported jar seemed to be the cause of the problem.

Thanks to @EJP and @Burkhard for quick responses to my query.

Komal Goyal
  • 233
  • 5
  • 17
  • Same here. At first, I simply used zip and a custom made MANIFEST.MF. Creating the jar and manifest with ANT then worked as expected. – jaw Feb 04 '15 at 15:12
0

are you using java 1.4? look at this bug 4338238

Ahiel
  • 493
  • 3
  • 11
  • More to the point, are you using an indexed JAR file? The bug is marked as 'unresolved', so the Java version doesn't come into it. – user207421 Dec 11 '12 at 07:34
  • I am using eclipse juno to export the jar for my project , I am using jdk1.6.30 on 64 bit windows machine.. @EJP I haven't explicitly selected any configuration for generation of indexed JAR. – Komal Goyal Dec 11 '12 at 08:30