jar文件如何执行?这些课程会被提取吗? [英] How does a jar file get executed? Do the classes get extracted somewhere?

查看:100
本文介绍了jar文件如何执行?这些课程会被提取吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道jar是一种压缩的存档文件格式,可以用作已编译的Java类和conf文件的容器.据我所知,要从压缩的容器文件中读取任何内容,首先需要将它们提取到某个地方.

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.

那么JVM如何在jar中执行类?它是否将罐子中的内容提取到临时位置,然后执行这些类?

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?

推荐答案

JVM能够从jar文件加载类或文件,而无需将jar提取为临时文件.

The JVM is capable of loading classes or files from a jar file without extracting the jar to temp files.

标准库中也可以使用此功能,请参见 JarFile 了解更多信息.

This functionality is also available to you in the standard library, see the JarFile for more information.

因此,不,JVM不会将jar提取到临时文件,类(和资源)只是按需加载.

So no, the JVM does not extract a jar to temp files, classes (and resources) are simply loaded on demand.

jar文件基本上是具有预定义条目"META-INF/MANIFEST.MF"的zip文件(仅在可执行jar情况下是必需的).此MANIFEST.MF条目(文件)包含JVM读取的一些信息.有关清单文件的更多信息:

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:

使用清单文件:基础

对于可执行jar,Manifest文件还包含应加载的主类,并调用其public static void main(String[])方法以启动应用程序. Main-Class清单条目指定主类:

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

这篇关于jar文件如何执行?这些课程会被提取吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆