Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4388202
Votes 48
Synopsis URLClassLoader fails when a URL points to a JAR inside another JAR
Category java:jar
Reported Against 1.3
Release Fixed
State 11-Closed, duplicate of 4418643, bug
Priority: 4-Low
Related Bugs 4418643
Submit Date 10-NOV-2000
Description


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


This is a resubmission of the bug following a review (ID 111906). I disagree
with the reviewer's conclusion that this is a duplicate of bug 4110602.

Since the submission, I hunted around a bit in the sources and found that the
source of the bug is the inability of java.net.JarURLConnection to handle
nested jars. There is a comment to that effect in the source.

I believe this bug can be easily fixed without impact. I can post a patch if so
desired.

ORIGINAL BUG REPORT
Say I have a jar, called setup.jar, which contains another jar, app.jar. Here's
the layout:

setup.jar
 +--META-INF
 |  |
 |  \MANIFEST.MF
 |
 +--Bootstrap.class
 |
 \--app.jar
    |
    +--META-INF
    |  |
    |  \MANIFEST.MF
    |
    \--App.class

NOTE: The manifest does not contain a Class-Path: directive. I handle the class
path explicitly by creating a new ClassLoader.

Now I'd like Bootstrap to locate app.jar using Class.getResource(), create a
URLClassLoader using the resulting URL, locate App.class using
ClassLoader.loadClass(), and invoke its main() method. But this fails with an
exception:

Exception in thread "main" java.lang.ClassNotFoundException: App
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
        at Bootstrap.main(Bootstrap.java:13)

Here are the sources used:

--------Bootstrap.java-----------

import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

public class Bootstrap {

	public static void main(String[] args) throws Exception {
		URL app = Bootstrap.class.getResource("/app.jar");
		//URL app = new URL("file:/C:/users/avik/cms/Tip/app.jar");
		System.out.println("app path: " + app);
		ClassLoader loader = new URLClassLoader(new URL[] { app });
		Class entry = loader.loadClass("App");
		Class[] argTypes = new Class[] { new String[0].getClass() };
		Method main = entry.getMethod("main", argTypes);
		main.invoke(null, new Object[] { args } );
	}

}
--------end--------------

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

-----app.manifest-------
Manifest-Version: 1.0
Main-Class: Bootstrap
--------end-------------

------testpackage.bat-----------
javac Bootstrap.java App.java
jar c0f app.jar App.class
jar c0mf app.manifest setup.jar app.jar Bootstrap.class
java -jar setup.jar
---------end-----------------

Create all files as specified and run testpackage.bat.
(Review ID: 111955) 
======================================================================
Posted Date : 2006-02-06 23:31:44.0
Work Around




Extract app.jar into a temporary location.
======================================================================
Evaluation
N/A
Comments
  
  Include a link with my name & email   

Submitted On 12-JAN-2001
sachan_alok
 I have created a JAR in which i included a frame class and
specified Main-class in its menifest file.when i run it 
through java -jar file.jar it runs fine. now i want to run 
it through JarRunner. so i put This JAR into LIb folder of
 JvaWebServer2.0. When i am Runnig it at command prompt 
through 
java JarRunner http://localhost:8080/filename.jar I got 
file not found exception. help me 


Submitted On 28-FEB-2001
Starrunner
I have a similar problem for a diffrent application:
I want to access files in a jar file which is again in jar file, by using URL (e.g. for images):
jar:jar:http://example.com/example.jar!/exampleInExample.jar!/TheRealExampe.jpg
Because in java.net.JarURLConnection.parseSpecs(URL url) the indexOf("!") is used,
instead of lastIndexOf("!") I get a:
"java.net.MalformedURLException: java.lang.NullPointerException: no !/ in spec"
when he is trying to retrieve the second Jar-Handler.
(StackTrace:
	at java.net.URL.<init>(URL.java:496)
	at java.net.URL.<init>(URL.java:376)
	at java.net.URL.<init>(URL.java:330)
	at java.net.JarURLConnection.parseSpecs(JarURLConnection.java:158)
	at java.net.JarURLConnection.<init>(JarURLConnection.java:141)
	at sun.net.www.protocol.jar.JarURLConnection.<init>(JarURLConnection.java:64)
	at sun.net.www.protocol.jar.Handler.openConnection(Handler.java:27)
	at java.net.URL.openConnection(URL.java:781)
	at java.net.URL.openStream(URL.java:798)
)
Seems to be the same bug. If not, I would like to be informed about it.


Submitted On 29-MAY-2001
wbsl
This is a bug in JDK 1.3.1 (Win2K SP1) too.  Also a bug if "jar:file:" protocol used.- PJH


Submitted On 15-AUG-2001
rsueess
bug!


Submitted On 15-NOV-2001
robofife
Rob
robofife@earthlink.net

I have had a problem loading a chat window on my 
PowereMac 8550. It worked about 2 weeks ago and 
now does not. I get the message "A Connection has 
failed" and I can tell that this occurs when the Applet 
loads cecause it says "Applet Loading" and then 
"Applet Closed" just before the Connection fails.

The java message reads:

An exception occurred:
java.lang.ClassNotFoundException: 
	at 
com.apple.mrj.JManager.JMAppletClassLoader_IMPL.l
oadClass(JMAppletClassLoaderOld.java)
	at 
com.apple.mrj.JManager.JMAppletClassLoader_IMPL.l
oadClass(JMAppletClassLoaderOld.java)
	at 
com.apple.mrj.JManager.JMAppletClassLoader_ROOT
.loadClass(JMAppletClassLoaderOld.java)
	at 
com.apple.mrj.JManager.JMAppletViewer_OLD.doLoad
Code(JMAppletViewerOld.java)
	at 
com.apple.mrj.JManager.JMAppletViewer_OLD.setStat
e(JMAppletViewerOld.java)
	at 
com.apple.mrj.JManager.JMViewerEvent.post(JMApplet
ViewerOld.java)
	at 
com.apple.mrj.JManager.AVDispatcherThread.run(JMA
ppletViewerOld.java)
Java Exception: java.lang.NullPointerException - 
Stack Trace:
java.lang.NullPointerException
	at 
java.awt.LightweightDispatcher.stopListeningForOther
Drags(Container.java)
	at 
java.awt.LightweightDispatcher.dispose(Container.java
)
	at java.awt.Container.removeNotify(Container.java)
	at java.awt.Window.dispose(Window.java)
	at java.awt.Frame.dispose(Frame.java)
	at 
com.apple.mrj.JManager.JMAppletViewer_OLD.setStat
e(JMAppletViewerOld.java)
	at 
com.apple.mrj.JManager.JMViewerEvent.post(JMApplet
ViewerOld.java)
	at 
com.apple.mrj.JManager.AVDispatcherThread.run(JMA
ppletViewerOld.java)


This is just part of it but I hope you get the jist. Please 
help me if you can. I have tried all that I know and I am 
desperate.

Sincerely,
Rob


Submitted On 20-FEB-2002
anupsoni
Similar probs with me too


Submitted On 21-MAY-2008
I fail to see how this is a duplicate of 4418643. 4418613 is an enhancement request and it may require to build upon this bug fix, but this is surely not a duplicate of that bug. Very weired.



PLEASE NOTE: JDK6 is formerly known as Project Mustang