• Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading of jar files for a Application  RSS feed

 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i keep 100's of jar files in my lib folder , some of them are not related to the Application . Will the container loads the required jar files or all of them which are placed in the lib folder??

Thanks in advance.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on the classloader implementation, but probably not.
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Depends on the classloader implementation, but probably not.


I wouldn't depend on that. If you reference a class and get a ClassNotFoundException, the only valid way to determine whether the class is findable or not is to search every single class directory and library JAR in the classpath. It may not load the JAR into memory, but there's still overhead for opening the JAR and searching its directory.

So I wouldn't just create a lib directory with all the JARs in the world in them just to make a one-size-fits-all-projects library.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom , from the explanation by you

I could not figure out , whether the classLoader loads the unnecessary jars or not ??
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RaviNada Kiran wrote:Tom , from the explanation by you

I could not figure out , whether the classLoader loads the unnecessary jars or not ??


You don't load a JAR, you load CLASSES. Which can be stored in JARs, in class directories or come from other places entirely, since all that a classloader is required to to is obtain a bytecode sequence and ensure that it gets interpreted as a Java Class (subject to security restrictions).

It's possible that a classloader might copy a JAR bit-for-bit into RAM, but unlikely, since that's not an especially convenient format for Java internal use, and in many projects, large chunks of the JAR might not ever be needed. So more often, only selected files (classes and class resources) within the JAR are loaded.

But in either case, to find a class, a JAR file has to be opened and the JAR directory has to be scanned. So for best performance, you'd want to limit the set of JARs being searched.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your time and great explanation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!