How does a jar file get executed? Do the classes get extracted somewhere?

Vivek :

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?

icza :

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get names of classes inside a jar file?

How do I get the path of the current executed file in Python?

How do I actually get somewhere in GUI programming?

How does Bash get the output of an executed program?

How does JavaScript get executed by web browsers?

How to extract a zip file and get the extracted components in a Share Extension in Swift

How do I get the directory that the currently executing jar file is in?

How do I get Android Studio to include resources in a .jar file?

Does stdout get stored somewhere in the filesystem or in memory?

wordpress: how do actions get executed?

How do chained functions get executed as goroutines?

How do I get the commands executed by Bazel

How do Async IO Coroutines get executed?

Get a file in a jar in jar

7zip - get name of extracted file

Pandas: "if" block does not get executed

How to get a number from a text file after a specific string in one of the lines somewhere on the line?

How to read a class file from an extracted jar file?

How does a non existent class get executed with selectAll?

How to get method signatures from a jar file?

How to get the file path location of a .jar dependency?

How to get the path of a running JAR file?

How to get a path to a resource in a Java JAR file

How to get a .txt File into a jar and read it

How to get a running Jar's file path?

How to get Google Directions to stay on a specified route to get somewhere?

Can you really get a trojan in an image file and if so how will it be executed?

How do we get a dictionary from classes,

after exporting a swing project to jar file will the code get executed every time it's launched?