This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Resource within jar file within jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Resource within jar file within jar file" Watch "Resource within jar file within jar file" New topic
Author

Resource within jar file within jar file

Fabricio Sanchez
Ranch Hand

Joined: Mar 11, 2003
Posts: 33
Hi There,

I have my main jar file containing classes and within that I have another jar file full of images and a library.xml file to manage those images as such:

utilities.jar
- com/esp/textures/JarTextureLibrary.class
- com/esp/textures/textures.jar
- library.xml
- bricks/brick_01.gif
- bricks/brick_02.gif
- etc...

In code I do the following


I then modify the URL by:


I then proceed to read the xml file from this newly created xmlString.

Now this doesn't work because of the multiple "!/" that appear on the final resulting URL giving me the following error message:

xml�library�location�is:�jar:file:/C:/current/lib/utilities.jar!/com/esp/textures/textures.jar!/library.xml
JAR entry com/esp/textures/textures.jar!/library.xml not found in C:\current\lib\utilities.jar

Any ideas how I can read not only the library file (library.xml) but also the images contained within it?

Is the only way to extract the textures.jar file locally and then try and access it?

Thank you in advance,

Regards,

Fabricio
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, not having the jar file inside another jar file would make things far easier. And if you made both jar files be in the classpath, you wouldn't have to change your existing code.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Here's an idea. Override/extend the File class with a class that will get its input from memory, say a byte array. Read the nested/contained jar file from the real jar file into the byte array. Then use the ZipFile constructor with your extended File class to process the jar file from memory.
 
 
subject: Resource within jar file within jar file
 
Similar Threads
reading a private method within a class
ANT: update JAR file
i'm so frustrated......deployment issue
Current directory
Loading Images