Invoke MR-JAR file verifier on command line without actually packaging

Uwe Schindler uschindler at
Wed Sep 27 10:31:42 UTC 2017


I am building a multi-release JAR file using Apache Ant (for Lucene, see

As build tools like Ant/Gradle/Maven are packaging JAR files on their own, not using the official JAR tool, I wanted to do a quick check if the resulting JAR file is valid. added some checks to compare method signatures and class file between the base and the META-INF/versions occurrences.

Is there a way to invoke those checks on an already packaged JAR file?


P.S.: Just a bit of background for those who are interested! This is a totally new way to create a MR JAR by just pacthing the already compiled class files before packaging as JAR file. The use case here is:
- We want to use java.util.Arrays / java.util.Objects static methods throughout Lucene, especially to improve bounds checks by having Java 9 use the intrinsics when accessing arrays/ByteBuffers. We have already seen a huge speed improvement for our implementation of the LZ4 compression!
- We need to be compatible with Java 8, but improve Java 9.
- So we compile all our Lucene classes against a "custom" variant of the interesting methods, located in a fallback classes we have implemented in our own org.apache.lucene.future.FutureArrays/FutureObjects.
- We do not want to duplicate our code by creating clonesof all .java files that use these methods and we still want to still compile against Java 8 - as this is the release JDK version! We want it automatic!

So our trick is new and also way cool: During packaging the JAR file we patch all class files using ASM's ClassRemapper and replace the Type org.apache.lucene.future.FutureArrays by java.util.Arrays, only for those that actually contain a reference to our own replacement methods. This is a 74-liner in Groovy! After patching we also place the patched files in the MR part of JAR file.

Patch can be seen here:

Especially this is how we patch our class files, way cool:

Uwe Schindler
uschindler at 
ASF Member, Apache Lucene PMC / Committer
Bremen, Germany

More information about the core-libs-dev mailing list