JDK-4459663 : Using executable jars erases CLASSPATH
  • Type: Enhancement
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 1.3.0,1.3.1_02,1.4.2,5.0,5.0u1
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS:
    generic,linux,windows_2000,windows_xp generic,linux,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 2001-05-16
  • Updated: 2013-12-10
  • Resolved: 2013-12-10
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
Name: bsC130419			Date: 05/16/2001


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)


[snoopy:~/test] jmwhit7% echo $CLASSPATH
/home/jmwhit7/jini1_1/lib/jini-core.jar:/home/jmwhit7/jini1_1/lib/jini-ext.jar:/
home/jmwhit7/jini1_1/lib/outrigger.jar:/home/jmwhit7/jini1_1/lib/outrigger-
dl.jar:.
[snoopy:~] jmwhit7% cd test
[snoopy:~/test] jmwhit7% ls
MANIFEST   Test.java
[snoopy:~/test] jmwhit7% cat Test.java
public class Test
{
  public static void main (String [] argv)
  {
    System.out.println("$CLASSPATH=" +
System.getProperty("java.class.path"));
  }
}
[snoopy:~/test] jmwhit7% cat MANIFEST
Main-Class: Test
[snoopy:~/test] jmwhit7% javac Test.java
[snoopy:~/test] jmwhit7% java Test
$CLASSPATH=/home/jmwhit7/jini1_1/lib/jini-core.jar:/home/jmwhit7/
jini1_1/lib/jini-ext.jar:/home/jmwhit7/jini1_1/lib/outrigger.jar:/home/
jmwhit7/jini1_1/lib/outrigger-dl.jar:.
[snoopy:~/test] jmwhit7% java -cp $CLASSPATH Test
$CLASSPATH=/home/jmwhit7/jini1_1/lib/jini-core.jar:/home/jmwhit7/
jini1_1/lib/jini-ext.jar:/home/jmwhit7/jini1_1/lib/outrigger.jar:/home/
jmwhit7/jini1_1/lib/outrigger-dl.jar:.
[snoopy:~/test] jmwhit7% java -classpath $CLASSPATH Test
$CLASSPATH=/home/jmwhit7/jini1_1/lib/jini-core.jar:/home/jmwhit7/
jini1_1/lib/jini-ext.jar:/home/jmwhit7/jini1_1/lib/outrigger.jar:/home/
jmwhit7/jini1_1/lib/outrigger-dl.jar:.
[snoopy:~/test] jmwhit7% java -Djava.class.path=$CLASSPATH Test
$CLASSPATH=/home/jmwhit7/jini1_1/lib/jini-core.jar:/home/jmwhit7/
jini1_1/lib/jini-ext.jar:/home/jmwhit7/jini1_1/lib/outrigger.jar:/home/
jmwhit7/jini1_1/lib/outrigger-dl.jar:.
[snoopy:~/test] jmwhit7% jar cfm Test.jar MANIFEST Test.class
[snoopy:~/test] jmwhit7% rm Test.class
[snoopy:~/test] jmwhit7% ls
MANIFEST   Test.jar   Test.java
[snoopy:~/test] jmwhit7% java -jar Test.jar
$CLASSPATH=Test.jar
[snoopy:~/test] jmwhit7% java -jar -cp $CLASSPATH Test.jar
$CLASSPATH=Test.jar
[snoopy:~/test] jmwhit7% java -jar -classpath $CLASSPATH Test.jar
$CLASSPATH=Test.jar
[snoopy:~/test] jmwhit7% java -jar -Djava.class.path=$CLASSPATH
Test.jar
$CLASSPATH=Test.jar
[snoopy:~/test] jmwhit7%
(Review ID: 124477) 
======================================================================

Name: rmT116609			Date: 01/29/2002


FULL PRODUCT VERSION :
java version "1.3.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)

A DESCRIPTION OF THE PROBLEM :
If I create an executable JAR file (by defining Main-Class
in the manifest file), and then start the java run-time
from the command line (java -cp
c:\theProjectNeedsThese.jar -jar c:\theProject.jar), the
application starts fine, but I get a NoClassDefFoundError
because the class files in theProjectNeedsThese.jar are not
recognized. The application only runs if I dump all of the
class files contained in theProjectNeedsThese.jar into
theProject.jar.

How do I allow the executable JAR file to access classes
contained in other JAR files?

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. generate a simple executable JAR file which imports
classes from a second JAR file
2. use the -jar option in the java runtime to start the
executable JAR

EXPECTED VERSUS ACTUAL BEHAVIOR :
expected: the imported classes in the second JAR file will
be accessible from the executable JAR.

actual: classes in the second JAR are not found.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NoClassDefFoundError:

This bug can be reproduced always.

CUSTOMER WORKAROUND :
Start the application using the .class file instead of the
executable JAR file.
(Review ID: 138942)
======================================================================
###@###.### 10/28/04 01:06 GMT

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
09-07-2004

PUBLIC COMMENTS ...
09-07-2004

WORK AROUND Name: bsC130419 Date: 05/16/2001 Dont use the jar file. ====================================================================== ###@###.### 2002-06-07 Put the additional classpath requirements (jar files) in the manifest in the jar file. See http://java.sun.com/j2se/1.4/docs/guide/jar/jar.html
07-06-2002

EVALUATION The launcher sets the classpath to the jar file when a jar is specified. It should instead prepend the jar file to the class path. ###@###.### 2001-08-14 As noted in the evaluation of 4356783, the current behavior is as specified. I have therefore reclassified this as an RFE rather than a bug. As such, it requires a specification change and therefore must wait until a dot release (i.e. 1.5) as opposed to a dot-dot release (i.e. 1.4.1). I have therefore recommitted this to Tiger (1.5). ###@###.### 2002-01-18 This should be considered as part of a broader examination of how classpaths and jars interact. ###@###.### 2003-10-21
18-01-2002