To Use or not to Use Jar Index

Starting from JDK 1.3, you can generate a index file for jar files. The purpose is to speed up classloading, just as indexed columns in database tables do to queries. Running this jar command generates a META-INF/INDEX.LIST for an existing jar file:

/cygdrive/c/tmp > dir main.jar
/cygdrive/c/tmp > jar i main.jar
/cygdrive/c/tmp > jar tf main.jar
Note that you cannot generate index while you are creating or updating the jar file. It has to be a separate step. You can only use the i options, not to be combined with other options like vf. For a complete documentations, see here.

Sounds like a great feature. Then I checked all jars in JDK 5, just to find none of the JDK jars has INDEX.LIST. I would think big jars like rt.jar would benefit from this feature. The only drawback I can think of is, when the jar file is subsequently updated, INDEX.LIST should also be updated to reflect any changes in class names. But normally users won't update rt.jar.

In JBoss 4.0.4, while most jar files do not have INDEX.LIST either, quite a few library and service archives do:
What factors keep people from using jar index file?


Kawu said...

I know that using Ant < jar > task with index="true" will create JARs hiding any Class-Path: ... entries from the manifest file MANIFEST.MF... So this will ALWAYS produce NoClassDefFoundError as soon as any class from one of the libraries in the Class-Path: ... manifest is requested to be loaded! Removing the INDEX.LIST file cures this (ridiculously strange) class path madness using JARs.

Anonymous said...

Please consider that the INDEX.LIST should speed up classloading only when using multiple jar files.

jar i my.jar
is useless.

But when using:
jar i main.jar libs1.jar libs2.jar
you will get an INDEX.LIST with package entries for all three jars in main.jar.

Consequently, in ant you have to use the indexjars sub-element for jar:
<indexjars name="lib*.jar"/>

Try it!

Anonymous said...

There is a caveat with ant and jar indexing, which is discussed here:
Bug report 6732405

and here:

New Plugin Forum

Anna said...

Great and Useful Article.

Online Java Training

Java Online Training India

Java Online Course

Java EE course

Java EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Course in Chennai

Java Online Training India

Unknown said...

I enjoyed on reading your blog post. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. Please visit my website, Friv 4000 Games is where all the free friv games.
Friv 4000

eMexoT said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

Internet Of Things training in electronic city