• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Couple of questions on jar files.

 
Pavan Kumar Dittakavi
Ranch Hand
Posts: 106
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have couple of questions related to jar files. As we know jar files are zipped files which contains classes and other manifest files in it.

1.My first question is, since it is a zipped file, how can an application locate a specific class from it at runtime...is it that applications extract the contents of jar files at runtime and then pick up an appropriate class?. Is there any special mechanisms that come into picture here?

2.Can jar files be delay loaded just as dlls.

Thanks,
Pavan.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do one thing. Copy any jar file to the desktop. Extract its contents to a folder. Then open the manifest file and see what does it contain. Let me know in case you have further doubts..
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why to the desktop?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Why to the desktop?

Not necessary to desktop only. Important thing is to copy at a separate place and then extract, not the original archive. There is a chance it might get corrupted.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extracting data from a jar file might corrupt the jar? That's extremely unlikely.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote: . . . Important thing is to copy at a separate place and then extract, not the original archive. There is a chance it might get corrupted.
Agree. Create a temporary folder, extract it inside that, then you can delete the folder.


And if you are careless and didn’t copy it, the jar file too
 
Pavan Kumar Dittakavi
Ranch Hand
Posts: 106
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,..sorry for the late reply. I have extracted a jar file and I could see different type of entries in it for instance, the version of the jar file, the jdk version that has been used for creating it and other entries like the main method that would get executed if one tries to run the jar file.

Just wanted to convey one of my questions again. Since jar file sort of compresses/binds together different classes, would they be unbundled/extracted when the jvm decides to run on of the classes' methods,...say for instance its main method.

Thanks,
Pavan.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pavan Kumar Dittakavi wrote:1.My first question is, since it is a zipped file, how can an application locate a specific class from it at runtime...is it that applications extract the contents of jar files at runtime and then pick up an appropriate class?. Is there any special mechanisms that come into picture here?

Unless it specifically says something about this in the Java language Specification, then it is probably entirely up to the JVM developer whether they extract all the files in one go or just extract them as needed.

Pavan Kumar Dittakavi wrote:2.Can jar files be delay loaded just as dlls.

Jar files are not loaded - classes are. And classes are only loaded when they are required.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic