United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6732405 : Jar indexing fails to include META-INF in index so service provider config fails

Details
Type:
Bug
Submit Date:
2008-07-31
Status:
Closed
Updated Date:
2010-04-04
Project Name:
JDK
Resolved Date:
2008-07-31
Component:
tools
OS:
windows_xp
Sub-Component:
jar
CPU:
x86
Priority:
P4
Resolution:
Duplicate
Affected Versions:
6u6
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Server VM (build 10.0-b22, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows XP
Windows Vista
Linux
probably all others

A DESCRIPTION OF THE PROBLEM :
When using
jar i main.jar lib1.jar lib2.jar
it is not possible to use service provider configuration in META-INF, because the META-INF is not listed in the INDEX.LIST in main.jar.
When providing e.g mail.jar as one of the libs, the mailcap file can not be found.

This makes jar indexing difficult to use, because all META-INF data must be manually transferred to the main jar.

If the reader never used jar indexing before, please look at:
http://www.ibm.com/developerworks/library/j-jar/index.html

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. take one jar file as main.jar and list lib1.jar in the class-path attribute of mainfest
2. take sun's mail.jar as lib1.jar
3. invoke
   jar i main.jar lib1.jar
4. Try to load the resource META-INF/mailcap via the classloader

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
we expect, that META-INF/mailcap is found, because lib1.jar is listed in class-path attribute of mainfest
ACTUAL -
resource is not found

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
As mentioned above, the jars can be organized in such a way, that all service provider information is found only in main.jar.
An ant snippet would look like this:

<jar
        index="true" jarfile="main.jar" basedir="classes">
	<manifest>
		<attribute name="Class-Path" value="lib1.jar lib2.jar"/>
	  </manifest>
	<indexjars path="${web.home}/applet/lib1.jar"/>
	<indexjars path="${web.home}/applet/lib2.jar"/>
 	<zipfileset src="lib1.jar" excludes="*.LIST *.RSA. *.SF" includes="META-INF/**"/>
    	<zipfileset src="lib2.jar" excludes="*.LIST *.RSA. *.SF" includes="META-INF/**"/>
</jar>

Can this be fixed, or is it just a lack of documention and understanding?

                                    

Comments
EVALUATION

mailcap can be read:

--- HelloWorld.java ---
public class HelloWorld {
    public static void main(String args[]) {
        System.out.println("Hello, world.");
    }
}

--- LoadMailcap.java ---
import java.io.*;
public class LoadMailcap {
    public static void main(String[] args) throws Throwable {
        new LoadMailcap().run();
    }

    void run() throws Throwable {
        BufferedReader r = new BufferedReader(
            new InputStreamReader(getClass().getResourceAsStream(
                                      "META-INF/mailcap")));
        String s = null;
        while ((s = r.readLine()) != null) {
            System.out.println(s);
        }
    }
}

--- Compile them and make a jar
% javac HelloWorld.java LoadMailcap.java
% jar cf hello.jar HelloWorld.class 

--- Create the jar index
% jar i hello.jar javamail-1.4.1/mail.jar

--- Demonstrate that the mailcap can be read
java -cp .:hello.jar LoadMailcap

(contents of javamail's mailcap are printed)

Please note that the synopsis and description mentions "service provider", but the issue described has nothing to do with service providers.

Also, despite the Description's claim, META-INF *is* listed in INDEX.LIST; here is the result from the above:

% cat META-INF/INDEX.LIST 
JarIndex-Version: 1.0

hello.jar
HelloWorld.class

javamail-1.4.1/mail.jar
META-INF
javax
javax/mail
javax/mail/event
javax/mail/search
javax/mail/util
javax/mail/internet
com/sun/mail/util
com/sun/mail/smtp
com/sun/mail/iap
com/sun/mail/imap
com/sun/mail/imap/protocol
com/sun/mail/pop3
com/sun/mail/handlers

Version of java used for above:
% java -version
java version "1.6.0_10-rc"
Java(TM) SE Runtime Environment (build 1.6.0_10-rc-b28)
Java HotSpot(TM) 64-Bit Server VM (build 11.0-b15, mixed mode)
                                     
2008-07-31



Hardware and Software, Engineered to Work Together