Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

MANIFEST.MF and INDEX.LIST

Thread view: 
Mistake - 18 Aug 2006 09:40 GMT
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.do;:WuuT?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
Thomas Weidenfeller - 18 Aug 2006 11:05 GMT
> 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.

Which is well documented, but java users typically prefer to ignore that
part of the documentation and learn it the hard way.

http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html#-jar

> 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).

Why are you using such an ancient Java version?

> 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).

Which is well documented.
http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html

>     - You can break a classpath line into several, but you have to make
> the line separation as CR[space][space] (see
[quoted text clipped - 6 lines]
>     - The classpath line must be finished by a carriage return (CR, LF,
> or CRLF).

All documented. The [space][space] issue is tricky, but also documented.
It allows to break single long pathes over multiple lines without
accidentally inserting a space in the path.

> 3. If there is a INDEX.LIST besides the MANIFEST.MF, then the class
> path specified in the manifest is ignored.

No, the manifest is initially used to create an index by the jar tool.
There is a bug in jar, which manifests itself in the way that index
entries are created with an absolute path instead of a relative one, but
that problem is easy to circumvent.

> 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.

No. This is often claimed, but not true. The default class loader can't
load jars from a jar (which is well documented), but that does in no way
mean one has to unpack and repack all jars (with stupid tools like
FatJar). Setting the Class-Path in the main jar and deploying multiple
jars (probably via JWS) works well.

There are people who claim they have written "jar-in-jar" class loaders.
I haven't seen a working one.

> Some (undesirable?) INDEX.LIST may
> pop out to the META-INF folder.

Index files in secondary (other than the main jar) jars are ignored.
Please submit a bug report to sun if you have a reproducible example
demonstrating otherwise.

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

The culprit was likely your attempt to build a "fat" jar.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.