Name: js151677 Date: 08/16/2004
FULL PRODUCT VERSION :
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When using the "-jar" option of the "java" command to run the Main-Class of a jar, it appears classes loaded from the jar can not use the jars specified in the classpath with the "-cp" option. At least using "Class.forName" calls result in ClassNotFoundException for classes in the normal classpath.
See "Steps to Reproduce" for a testcase.
What should be used instead of Class.forName?
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect the classes added to the standard classpath to be available to the classes inside the jars using the normal "Class.forName" as I did not explicitely used any custom classloader.
ACTUAL -
An exception is thrown when using Class.forName.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Use these two classes and the manifest:
src/mypackage/A.java
package mypackage;
public class A {
public static void main(String[] args) throws Exception {
Class.forName("mypackage.B");
}
}
src/mypackage/B.java
package mypackage;
public class B {
}
src/manifest.mf
Main-Class: mypackage.A
Once compiled, build A.jar with mypackage/A.class and manifest.mf:
jar cvfm A.jar manifest.mf mypackage\A.class
build B.jar with mypackage/B.class:
jar cvf B.jar mypackage\B.class
now run "java -cp A.jar;B.jar mypackage.A". It runs correctly.
if you run "java -cp B.jar -jar A.jar" it throws ClassNotFoundException mypackage.B.
---------- END SOURCE ----------
(Incident Review ID: 296132)
======================================================================
- duplicates
-
JDK-4356783 Running java.exe with "-jar" ignores the classpath
-
- Closed
-