This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Lazy loading resources inside jars  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

I've put together a little JarLoader class as an attempt to provide a facility
for running standalone jarred applications. Basically it's an extension of Simon Tuffs one-jar sourceforge project which I can't recommend enough. It's a really great project and a wonderful introduction to the use of the JAR API.

http://one-jar.sourceforge.net

He also has a great plugin for Eclipse that allows you to peer into jars in your workspace and amend them. Top notch stuff.

My problem is this:-

I have a jar like the following.
=======================
JarA.jar
|
|-->ClassA.class
|-->JarB.jar
|
|---->ClassB.class

i.e. jarA contains the class, ClassA, and a another jar, jarB. jarB contains
the class, ClassB.

Using the jar api I can retrieve and load ClassB using the following code.



I've written a little catalog function that traverses a jar and catalogs all the classes that it finds. however, and this is the crux of the problem, it doesn't load them until the JarClassLoader is prompted for the class at runtime. i.e. lazy loading. I don't want to have to iterate over the entries in the internal file everytime I want to load a resource from it. The catalog function saves along with the description of the resource, the size of the resource and the offset into the archive where the resource began.

To calculate the offset, it simply increments an offset by the size of each entry it comes across during the original traversal. Alas I don't think this is giving me the correct offset value at all. When it comes time to load the resource, it finds the location of the archive, opens a JarInputStream to it and then skips along by the offset and attempts then to read the recorded number of bytes that should specify the archived entry. Alas this is not working for me.

Therefore while I can lazily load the classes I have to resort to iterating over all the entries within the archive where my resource resides. So while it's lazy it is not very fast. If I could implement this offset loading then surely it would be a lot faster especially in archives where there are hundreds of entries.

Anyone any ideas? Maybe someone is familiar enough with the JAR api to be able to recommend a better way to get the offset into the jar file? Perhaps this isn't plausible? Any suggestions are most welcome.

Thanks,
Mark.
[ November 29, 2005: Message edited by: Mark Gargin ]
 
Villains always have antidotes. They're funny that way. Here's an antidote disquised as a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!