Jar Manifest文件使用的困惑 [英] Confusion on Uses of Jar Manifest File

查看:100
本文介绍了Jar Manifest文件使用的困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读使用jar工具打包java应用程序。我注意到在META-INF目录下创建了一个清单文件。对于一个简单的应用程序,感觉就像,它没有用处。我在stackoverflow上搜索了解Manifest文件的用法。我遇到了 UsesOfManifestFile 。在阅读答案时,我对第2点和第3点感到困惑: -

I am reading packaging java applications with jar tool. I noticed a manifest file is created under META-INF directory. For a simple application, it felt like, it's serves no purpose. I searched on stackoverflow to understand the usages of Manifest file. I came across UsesOfManifestFile. While reading the answer, i got confused on point 2 and 3 which are :-


  1. 什么是下载扩展?我无法理解答案中的概念。

  2. 密封罐子是什么意思?它在下面给出了一个例子




名称:myCompany / MyPackage / Sealed:true

Name: myCompany/MyPackage/ Sealed: true

放置此类信息有什么用?有人可以详细说明这些要点。
谢谢。

What is the use of putting such information? Can someone elaborate on these points. Thanks.

推荐答案

清单文件类似于java程序运行jar的指导说明。创建清单时,它将保存关键信息,例如对主程序的引用。当java程序运行你的jar时它不知道从哪里开始,所以它看起来是一行的清单,告诉它使用main方法的类在哪里,因此它有一个程序的起点。另一个用途是类路径行,它将告诉程序在jar中找到任何第三方库的位置,否则java程序将无法找到它们。

The manifest file is like the guidance instructions for the java program to run the jar. When the manifest is created it will hold crucial information, for example a reference to the main program. When the java program runs your jar it doesn't know where to start, so it look sin the manifest for a line telling it where the class with the main method is so it has a start point for the program. Another use is a classpath line, which will tell the program where to find any 3rd party library's in the jar are, otherwise again, the java program won't find them.

有一系列数据可以存储在清单文件中,我建议查看关于他们的Oracle信息,看看是否会更清楚它。

There is a range of data that can be stored in the manifest file, I would recommend checking out the Oracle information on them and seeing if that clears it up a bit more.

编辑: 从Oracle网站上了解您的示例:

From the Oracle site regarding your example:


JAR文件中的包可以选择性地密封,这意味着所有类都定义了在该包中必须存档在同一个JAR文件中。例如,您可能希望密封包,以确保软件中类之间的版本一致性。

Packages within JAR files can be optionally sealed, which means that all classes defined in that package must be archived in the same JAR file. You might want to seal a package, for example, to ensure version consistency among the classes in your software.

通过添加Sealed标头密封JAR文件中的包在清单中,它具有一般形式:

You seal a package in a JAR file by adding the Sealed header in the manifest, which has the general form:

名称:myCompany / myPackage /
密封:true
值myCompany / myPackage /是要密封的包裹的名称。

Name: myCompany/myPackage/ Sealed: true The value myCompany/myPackage/ is the name of the package to seal.

请注意,包裹名称必须以/\".

Note that the package name must end with a "/".

$ b $结尾b

这似乎意味着您在程序中使用的任何和所有类 必须 都在同一个jar文件中。

What this appears to mean is that any and all classes that you use in your program must be within the same jar file.

编辑2 (评论回复)

EDIT 2 (For comment response)

清单可能包含以下行:

Main-Class: com.mkyong.awt.AwtExample  

当javaw.exe(我认为)运行你的runnable jar时,它不知道从哪里开始,所有java程序都通过main运行方法, 但是如果你在jar中说了50个类文件,它就不知道哪一个有主要方法可以从哪个开始。它将查看清单文件,读取上面的行并认为正确,main方法在包com.mkyong.awt中,类是AwtExample,然后它找到该类并从该main方法运行程序。 jar中最基本的功能是告诉运行jar的java程序在哪里找到运行jar所需的东西。

When the javaw.exe (I think) runs your runnable jar, it has no idea where to start from, all java programs run via a main method, but if you have say 50 class files in your jar, it has no idea which one has the main method to start from. It will look at the manifest file, reads your above line and thinks right, the main method is in the package com.mkyong.awt and the class is AwtExample, it then finds this class and runs the program from that main method. It's most basic function within the jar is to tell the java program running the jar where to find the stuff it needs to run your jar.

注意:示例清单条目来了从一个小的教程,其中显示了如何创建一个简单的可运行jar。

Note: that example manifest entry came from a little tutorial which shows how to create a simple runnable jar.

祝你好运!

这篇关于Jar Manifest文件使用的困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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