Name: nt126004 Date: 08/22/2002
FULL PRODUCT VERSION :
java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)
and
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Linux matrix.piro.net 2.4.19-xfs #3 SMP Mon Aug 5 15:44:31
CEST 2002 i686 unknown
ADDITIONAL OPERATING SYSTEMS :
A DESCRIPTION OF THE PROBLEM :
The URLClassLoader does work with jar: URLs.
Assume, that you have a JAR with the following content:
C1.class
x2.jar (which contains C2.class)
C1 needs classes in "jar:file:x1.jar!/x2.jar" - so it
constructs a URLClassLoader with that URL - but the CL does
not find the classes...
Mentioning the JAR URL on the command line using -classpath
or setting it in the Manifest "Class-Path" attribute does
not work at all (no error messages)
The testcase below illustrates the bug.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create the 4 source files (see "Source Code")
2. run test.sh (on Unix or cygwin - I tested it on Linux)
EXPECTED VERSUS ACTUAL BEHAVIOR :
The actual result is a ClassNotFoundException.
I expect classes to be loaded using the URLClassLoader with
jar: URLs.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ClassNotFoundException: C2
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:217)
at C1.main(C1.java:10)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
You need 4 files (C1.java, C2.java, manifest and test.sh). Just run test.sh to
reproduce the bug.
C1.java:
import java.net.*;
import java.lang.reflect.*;
public class C1 {
public static void main(String args[]) throws Throwable {
System.out.println("C1: first");
URL u=new URL("jar:file:x1.jar!/x2.jar");
u.openConnection().getInputStream().close();
URLClassLoader cl=new URLClassLoader(new URL[]{u});
System.out.println("C1: second");
Class cls=Class.forName("C2",true,cl);
System.out.println("C1: third");
Method mth=cls.getMethod("main",new Class[]{String[].class});
mth.invoke(null,new Object[]{args});
}
}
C2.java:
public class C2 {
public static void main(String args[]) throws Throwable {
System.out.println("C2: here I am");
}
}
manifest:
Main-Class: C1
test.sh:
#!/bin/sh
echo "compiling..."
javac C1.java C2.java
echo "creating x2.jar..."
jar cf x2.jar C2.class
echo "creating x1.jar..."
jar cfm x1.jar manifest C1.class x2.jar
echo "executing..."
java -jar x1.jar
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
I created my own class loader.
(Review ID: 163476)
======================================================================