Nice summary for java jar: class path, index.list and manifest.mf

      08-18-2006
Hello everybody,

I’ve just spent some hours (late hours) fighting against the classpath
in JAR archives, the MANIFEST.MF file and the INDEX.LIST file.

I just want to mention together some of the information I gathered
through internet (and tested on my own). They may be useful to someone
else. I’m not completely sure to have understood everything, though.

1. You can’t launch a Java application using the “java” command, and
using both the -jar (specifies a jar file) option and the -cp
(specifies a classpath) option. They’re mutually exclusive. If you use
the -jar option, then the -cp is completely ignored.

2. You can add a ‘Class-Path’ entry in the manifest file, MANIFEST.MF
file (see http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html). But
you have to be very cautious with it. Several rules apply in the way
you specify your class path:
– Class-Path line can’t be longer than 72 chars (nice one).
– You can break a classpath line into several, but you have to make
the line separation as CR[space][space] (see
http://bugs.sun.com/bugdatabase/view…bug_id=4295946)
– All classpath entries are relatives to the jar archive containing
the manifest.
– A single dot ‘.’ stands for the folder where the jar archive is
placed:
– Classpaths are separated by ‘ ‘ (one space).
– The classpath line must be finished by a carriage return (CR, LF,
or CRLF).

3. If there is a INDEX.LIST besides the MANIFEST.MF, then the class
path specified in the manifest is ignored. This can happen if some of
the jar libraries included in your jar have this INDEX.LIST file. When
you build your jar, you have to break up all jar libraries, and
recompile them into one big fat jar. Some (undesirable?) INDEX.LIST may
pop out to the META-INF folder.

The last point took me some time to figure out. In my case, the culprit
was mysql-connector-java-3.1.11-bin.jar.

Regards,
Mistake
Refers from http://www.velocityreviews.com/forums/t365098-manifest-mf-and-index-list.html.

Besides oracle doc on jar, Once the class loader finds a INDEX.LIST file in a particular jar file, it always trusts the information listed in it. If a mapping is found for a particular class, but the class loader fails to find it by following the link, an InvalidJarIndexException is thrown. When this occurs, the application developer should rerun the jar tool on the extension to get the right information into the index file.
Refer to http://docs.oracle.com/javase/1.4.2/docs/guide/jar/jar.html.

Advertisements

Author: lwpro2

Java J2EE professional

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s