首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

JAR 资料规范(年底了,最近两天比较忙,可能要慢一点)

2012-07-28 
JAR 文件规范(年底了,最近两天比较忙,可能要慢一点)英文版本:?http://docs.oracle.com/javase/6/docs/tech

JAR 文件规范(年底了,最近两天比较忙,可能要慢一点)


英文版本:

?

http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html

?

样例清单文件:

?

?

每个文件的实现必须支持相当于65535字节(不是字符)的头部值和65535个头部。 They might run out of memory, but there should not be hard-coded limits below these values.

签名者:
It is technically possible that different entities may use different signing algorithms to share a single signature file. This violates the standard, and the extra signature may be ignored.算法:
本版本没有强制执行摘要算法或签名算法。然而,MD5或SHA摘要算法必须至少支持其一。JAR 索引概述

Since 1.3, JarIndex is introduced to optimize the class searching process of class loaders for network applications, especially applets. Originally, an applet class loader uses a simple linear search algorithm to search each element on its internal search path, which is constructed from the "ARCHIVE" tag or the "Class-Path" main attribute. The class loader downloads and opens each element in its search path, until the class or resource is found. If the class loader tries to find a nonexistent resource, then all the jar files within the application or applet will have to be downloaded. For large network applications and applets this could result in slow startup, sluggish response and wasted network bandwidth. The JarIndex mechanism collects the contents of all the jar files defined in an applet and stores the information in an index file in the first jar file on the applet's class path. After the first jar file is downloaded, the applet class loader will use the collected content information for efficient downloading of jar files.

The existing jar tool is enhanced to be able to examine a list of jar files and generate directory information as to which classes and resources reside in which jar file. This directory information is stored in a simple text file named INDEX.LIST in the META-INF directory of the root jar file. When the classloader loads the root jar file,? it reads the INDEX.LIST file and uses it to construct a hash table of mappings from file and package names to lists of jar file names. In order to find a class or a resource, the class loader queries the hashtable to find the proper jar file and then downloads it if necessary.

Once the class loader finds a INDEX.LIST file in a particular jar file, it always trusts the information listed in it. If a mapping is found for a particular class, but the class loader fails to find it by following the link, an InvalidJarIndexException is thrown. When this occurs, the application developer should rerun the jar tool on the extension to get the right information into the index file.

To prevent adding too much space overhead to the application and to speed up the construction of the in-memory hash table, the INDEX.LIST file is kept as small as possible. For classes with non-null package names, mappings are recorded at the package level. Normally one package name is mapped to one jar file, but if a particular package spans more than one jar file, then the mapped value of this package will be a list of jar files. For resource files with non-empty directory prefixes, mappings are also recorded at the directory level.? Only for classes with null package name, and resource files which reside in the root directory, will the mapping be recorded at the individual file level.

索引文件声明

The INDEX.LIST file contains one or more sections each separated by a single blank line. Each section defines the content of a particular jar file, with a header defining the jar file path name, followed by a list of package or file names, one per line.? All the jar file paths are relative to the code base of the root jar file. These path names are resolved in the same way as the current extension mechanism does for bundled extensions.

The UTF-8 encoding is used to support non ASCII characters in file or package names in the index file.
?

声明

??? index file :?????????????????? version-info blankline section*
??? version-info :????????????? JarIndex-Version: version-number
??? version-number :??????? digit+{.digit+}*
??? section :????????????????????? body blankline
??? body :???????????????????????? header name*
??? header :????????????????????? char+.jar newline
??? name :??????????????????????? char+ newline
??? char :????????????????????????? any valid Unicode character except NULL, CR andLF
??? blankline:??????????????????? newline newline
??? newline :????????????????????? CR LF | LF | CR (not followed by LF)
??? digit:?????????????????????????? {0-9}
?
运行jar -i.会产生 INDEX.LIST 文件。查看 jar 帮助页面获取更多细节。

向后兼容

The new class loading scheme is totally backward compatible with applications developed on top of the current extension mechanism.? When the class loader loads the first jar file and an INDEX.LIST file is found in the META-INF directory, it would construct the index hash table and use the new loading scheme for the extension. Otherwise, the class loader will simply use the original linear search algorithm.

服务供应商概述

Files in the META-INF/services directory are service provider configuration files. A service is a well-known set of interfaces and (usually abstract) classes. A service provider is a specific implementation of a service. The classes in a provider typically implement the interfaces and subclass the classes defined in the service itself. Service providers may be installed in an implementation of the Java platform in the form of extensions, that is, jar files placed into any of the usual extension directories. Providers may also be made available by adding them to the applet or application class path or by some other platform-specific means.

A service is represented by an abstract class. A provider of a given service contains one or more concrete classes that extend this service class with data and code specific to the provider. This provider class will typically not be the entire provider itself but rather a proxy that contains enough information to decide whether the provider is able to satisfy a particular request together with code that can create the actual provider on demand. The details of provider classes tend to be highly service-specific; no single class or interface could possibly unify them, so no such class has been defined. The only requirement enforced here is that provider classes must have a zero-argument constructor so that they may be instantiated during lookup.
?

供应商程序配置文件

一个服务提供者 identifies itself by placing a provider-configuration file in the resource directory META-INF/services. The file's name should consist of the fully-qualified name of the abstract service class. The file should contain a newline-separated list of unique concrete provider-class names. Space and tab characters, as well as blank lines, are ignored. The comment character is '#' (0x23); on each line all characters following the first comment character are ignored. The file must be encoded in UTF-8.

?


热点排行