- Jar file java api
- Class JarFile
- Field Summary
- Fields declared in class java.util.zip.ZipFile
- Constructor Summary
- Method Summary
- Jar file java api
- Field Summary
- Fields inherited from class java.util.zip.ZipFile
- Constructor Summary
- Method Summary
- Methods inherited from class java.util.zip.ZipFile
- Methods inherited from class java.lang.Object
- Field Detail
- MANIFEST_NAME
- LOCSIG
- EXTSIG
- CENSIG
- ENDSIG
- LOCHDR
- EXTHDR
- CENHDR
- ENDHDR
- LOCVER
- LOCFLG
- LOCHOW
- LOCTIM
- LOCCRC
- LOCSIZ
- LOCLEN
- LOCNAM
- LOCEXT
- EXTCRC
- EXTSIZ
- EXTLEN
- CENVEM
- CENVER
- CENFLG
- CENHOW
- CENTIM
- CENCRC
- CENSIZ
- CENLEN
- CENNAM
- CENEXT
- CENCOM
- CENDSK
- CENATT
- CENATX
- CENOFF
- ENDSUB
- ENDTOT
- ENDSIZ
- ENDOFF
- ENDCOM
- Constructor Detail
- JarFile
- JarFile
- JarFile
- JarFile
- JarFile
- Method Detail
- getManifest
- getJarEntry
- getEntry
- entries
- stream
- getInputStream
- Class JarFile
Jar file java api
Class JarFile
The JarFile class is used to read the contents of a jar file from any file that can be opened with java.io.RandomAccessFile . It extends the class java.util.zip.ZipFile with support for reading an optional Manifest entry, and support for processing multi-release jar files. The Manifest can be used to specify meta-information about the jar file and its entries. A multi-release jar file is a jar file that contains a manifest with a main attribute named «Multi-Release», a set of «base» entries, some of which are public classes with public or protected methods that comprise the public interface of the jar file, and a set of «versioned» entries contained in subdirectories of the «META-INF/versions» directory. The versioned entries are partitioned by the major version of the Java platform. A versioned entry, with a version n , 8 < n , in the "META-INF/versions/" directory overrides the base entry as well as any entry with a version number i where 8 < i < n . By default, a JarFile for a multi-release jar file is configured to process the multi-release jar file as if it were a plain (unversioned) jar file, and as such an entry name is associated with at most one base entry. The JarFile may be configured to process a multi-release jar file by creating the JarFile with the JarFile(File, boolean, int, Runtime.Version) constructor. The Runtime.Version object sets a maximum version used when searching for versioned entries. When so configured, an entry name can correspond with at most one base entry and zero or more versioned entries. A search is required to associate the entry name with the latest versioned entry whose version is less than or equal to the maximum version (see getEntry(String) ). Class loaders that utilize JarFile to load classes from the contents of JarFile entries should construct the JarFile by invoking the JarFile(File, boolean, int, Runtime.Version) constructor with the value Runtime.version() assigned to the last argument. This assures that classes compatible with the major version of the running JVM are loaded from multi-release jar files. If the verify flag is on when opening a signed jar file, the content of the jar entry is verified against the signature embedded inside the manifest that is associated with its path name . For a multi-release jar file, the content of a versioned entry is verfieid against its own signature and JarEntry.getCodeSigners() returns its own signers. Please note that the verification process does not include validating the signer's certificate. A caller should inspect the return value of JarEntry.getCodeSigners() to further determine if the signature can be trusted. Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.
- jdk.util.jar.version can be assigned a value that is the String representation of a non-negative integer
- jdk.util.jar.enableMultiRelease can be assigned one of the three String values true, false, or force. The value true, the default value, enables multi-release jar file processing. The value false disables multi-release jar processing, ignoring the «Multi-Release» manifest attribute, and the versioned directories in a multi-release jar file if they exist. Furthermore, the method isMultiRelease() returns false. The value force causes the JarFile to be initialized to runtime versioning after construction. It effectively does the same as this code: (new JarFile(File, boolean, int, JarFile.runtimeVersion()) .
Field Summary
Fields declared in class java.util.zip.ZipFile
Constructor Summary
Method Summary
Returns the version that represents the effective runtime versioned configuration of a multi-release jar file.
Jar file java api
The JarFile class is used to read the contents of a jar file from any file that can be opened with java.io.RandomAccessFile . It extends the class java.util.zip.ZipFile with support for reading an optional Manifest entry. The Manifest can be used to specify meta-information about the jar file and its entries. Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown. If the verify flag is on when opening a signed jar file, the content of the file is verified against its signature embedded inside the file. Please note that the verification process does not include validating the signer’s certificate. A caller should inspect the return value of JarEntry.getCodeSigners() to further determine if the signature can be trusted.
Field Summary
Modifier and Type | Field and Description |
---|---|
static int | CENATT |
static int | CENATX |
static int | CENCOM |
static int | CENCRC |
static int | CENDSK |
static int | CENEXT |
static int | CENFLG |
static int | CENHDR |
static int | CENHOW |
static int | CENLEN |
static int | CENNAM |
static int | CENOFF |
static long | CENSIG |
static int | CENSIZ |
static int | CENTIM |
static int | CENVEM |
static int | CENVER |
static int | ENDCOM |
static int | ENDHDR |
static int | ENDOFF |
static long | ENDSIG |
static int | ENDSIZ |
static int | ENDSUB |
static int | ENDTOT |
static int | EXTCRC |
static int | EXTHDR |
static int | EXTLEN |
static long | EXTSIG |
static int | EXTSIZ |
static int | LOCCRC |
static int | LOCEXT |
static int | LOCFLG |
static int | LOCHDR |
static int | LOCHOW |
static int | LOCLEN |
static int | LOCNAM |
static long | LOCSIG |
static int | LOCSIZ |
static int | LOCTIM |
static int | LOCVER |
static String | MANIFEST_NAME |
Fields inherited from class java.util.zip.ZipFile
Constructor Summary
Method Summary
Methods inherited from class java.util.zip.ZipFile
Methods inherited from class java.lang.Object
Field Detail
MANIFEST_NAME
LOCSIG
public static final long LOCSIG
EXTSIG
public static final long EXTSIG
CENSIG
public static final long CENSIG
ENDSIG
public static final long ENDSIG
LOCHDR
public static final int LOCHDR
EXTHDR
public static final int EXTHDR
CENHDR
public static final int CENHDR
ENDHDR
public static final int ENDHDR
LOCVER
public static final int LOCVER
LOCFLG
public static final int LOCFLG
LOCHOW
public static final int LOCHOW
LOCTIM
public static final int LOCTIM
LOCCRC
public static final int LOCCRC
LOCSIZ
public static final int LOCSIZ
LOCLEN
public static final int LOCLEN
LOCNAM
public static final int LOCNAM
LOCEXT
public static final int LOCEXT
EXTCRC
public static final int EXTCRC
EXTSIZ
public static final int EXTSIZ
EXTLEN
public static final int EXTLEN
CENVEM
public static final int CENVEM
CENVER
public static final int CENVER
CENFLG
public static final int CENFLG
CENHOW
public static final int CENHOW
CENTIM
public static final int CENTIM
CENCRC
public static final int CENCRC
CENSIZ
public static final int CENSIZ
CENLEN
public static final int CENLEN
CENNAM
public static final int CENNAM
CENEXT
public static final int CENEXT
CENCOM
public static final int CENCOM
CENDSK
public static final int CENDSK
CENATT
public static final int CENATT
CENATX
public static final int CENATX
CENOFF
public static final int CENOFF
ENDSUB
public static final int ENDSUB
ENDTOT
public static final int ENDTOT
ENDSIZ
public static final int ENDSIZ
ENDOFF
public static final int ENDOFF
ENDCOM
public static final int ENDCOM
Constructor Detail
JarFile
Creates a new JarFile to read from the specified file name . The JarFile will be verified if it is signed.
JarFile
public JarFile(String name, boolean verify) throws IOException
JarFile
Creates a new JarFile to read from the specified File object. The JarFile will be verified if it is signed.
JarFile
public JarFile(File file, boolean verify) throws IOException
JarFile
public JarFile(File file, boolean verify, int mode) throws IOException
Creates a new JarFile to read from the specified File object in the specified mode. The mode argument must be either OPEN_READ or OPEN_READ | OPEN_DELETE.
Method Detail
getManifest
public Manifest getManifest() throws IOException
getJarEntry
getEntry
entries
stream
Return an ordered Stream over the ZIP file entries. Entries appear in the Stream in the order they appear in the central directory of the ZIP file.
getInputStream
public InputStream getInputStream(ZipEntry ze) throws IOException
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
Class JarFile
The JarFile class is used to read the contents of a jar file from any file that can be opened with java.io.RandomAccessFile . It extends the class java.util.zip.ZipFile with support for reading an optional Manifest entry, and support for processing multi-release jar files. The Manifest can be used to specify meta-information about the jar file and its entries.
A multi-release jar file is a jar file that contains a manifest with a main attribute named «Multi-Release», a set of «base» entries, some of which are public classes with public or protected methods that comprise the public interface of the jar file, and a set of «versioned» entries contained in subdirectories of the «META-INF/versions» directory. The versioned entries are partitioned by the major version of the Java platform. A versioned entry, with a version n , 8 < n , in the "META-INF/versions/" directory overrides the base entry as well as any entry with a version number i where 8 < i < n .
By default, a JarFile for a multi-release jar file is configured to process the multi-release jar file as if it were a plain (unversioned) jar file, and as such an entry name is associated with at most one base entry. The JarFile may be configured to process a multi-release jar file by creating the JarFile with the JarFile(File, boolean, int, Runtime.Version) constructor. The Runtime.Version object sets a maximum version used when searching for versioned entries. When so configured, an entry name can correspond with at most one base entry and zero or more versioned entries. A search is required to associate the entry name with the latest versioned entry whose version is less than or equal to the maximum version (see getEntry(String) ).
Class loaders that utilize JarFile to load classes from the contents of JarFile entries should construct the JarFile by invoking the JarFile(File, boolean, int, Runtime.Version) constructor with the value Runtime.version() assigned to the last argument. This assures that classes compatible with the major version of the running JVM are loaded from multi-release jar files.
If the verify flag is on when opening a signed jar file, the content of the jar entry is verified against the signature embedded inside the manifest that is associated with its path name . For a multi-release jar file, the content of a versioned entry is verfieid against its own signature and JarEntry.getCodeSigners() returns its own signers. Please note that the verification process does not include validating the signer’s certificate. A caller should inspect the return value of JarEntry.getCodeSigners() to further determine if the signature can be trusted.
Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.
- jdk.util.jar.version can be assigned a value that is the String representation of a non-negative integer
- jdk.util.jar.enableMultiRelease can be assigned one of the three String values true, false, or force. The value true, the default value, enables multi-release jar file processing. The value false disables multi-release jar processing, ignoring the «Multi-Release» manifest attribute, and the versioned directories in a multi-release jar file if they exist. Furthermore, the method isMultiRelease() returns false. The value force causes the JarFile to be initialized to runtime versioning after construction. It effectively does the same as this code: (new JarFile(File, boolean, int, JarFile.runtimeVersion()) .