2

Separating this out of the initial question that I had, assuming this to be generic enough. How can I prior to using an artifact check if it is a multi-release jar.

Multi-Release: true

I know its possible looking manually into the MANIFEST.MF within the META-INF of the jar for the above attribute, but is there a command line option available for this?

Maybe I am missing something already existing with some other name or blind to something very obvious. But I tried looking out for such an option in jar and java tool as well to no success.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • When I looked for a way to peek into a JARs manifest, I found no solution either. I think there's no way around [unzipping](https://stackoverflow.com/a/46662468/2525313). – Nicolai Parlog Oct 10 '17 at 09:52
  • 4
    Nicolai is correct, the `jar` tool does not provide options to quickly see if a JAR file is a MR JAR. The simplest is to use `jar --file= --list` and look for META-INF/versions in the list. Yes, there is a corner case where someone adds a version section without the Multi-Release attribute in the manifest. – Alan Bateman Oct 10 '17 at 10:40

1 Answers1

5

jar only supports special operations on the manifest file during creation and updating. You can get by with this:

unzip -p file.jar META-INF/MANIFEST.MF | grep "Multi-Release: true"

Other than that, JarFile includes the following new method that could be useful:

boolean isMultiRelease(): Return true when this JAR file is a multi-release JAR file.

neuhaus
  • 3,886
  • 1
  • 10
  • 27