We know that jar
is a compressed archive file format which acts as a container for compiled java classes and conf files. As far as I know, for reading any contents from a compressed container file, first they need to be extracted somewhere.
So how does the JVM execute classes inside the jar? Does it extract the contents of the jar to a temp location and then executes the classes?
Does it extract the contents of the jar to a temp location and then executes the classes? The packaged data is extracted directly into memory and not stored temporarily on disk.
Since JAR files work like ZIP files, you can use an archive program like WinRAR to extract them. For Windows users, you can install Java SE to use the 'jar' extraction command in the Command Prompt.
The jar-file argument is the filename (or path and filename) of the JAR file from which to extract files. archived-file(s) is an optional argument consisting of a space-separated list of the files to be extracted from the archive. If this argument is not present, the Jar tool will extract all the files in the archive.
The JAR file contains the TicTacToe class file and the audio and images directory, as expected. The output also shows that the JAR file contains a default manifest file, META-INF/MANIFEST. MF, which was automatically placed in the archive by the JAR tool.
The JVM is capable of loading classes or files from a jar file without extracting the jar to temp files.
This functionality is also available to you in the standard library, see the JarFile
for more information.
So no, the JVM does not extract a jar to temp files, classes (and resources) are simply loaded on demand.
A jar file is basically a zip file with a predefined entry "META-INF/MANIFEST.MF"
(this is only mandatory in case of an executable jar). This MANIFEST.MF
entry (file) contains some information read by the JVM. More on the Manifest files:
Working with Manifest Files: The Basics
In case of an executable jar the Manifest file also contains the main class that should be loaded and whose public static void main(String[])
method to be called in order to start the application. The Main-Class
manifest entry specifies the main class:
Main-Class: classname
No The jvm extracts the jar file to the memory and not to the file. It reads the MANIFEST.MF inside META-INF which has an entry for the main class. Jvm looks for the public static void main class inside this main class. This is how jvm finds the main class and executes the executable jar files
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With