Java tools jar windows

Java tools jar windows

Manipulates Java Archive (JAR) files.

Synopsis

Create JAR file

Update JAR file

Extract JAR file

List Contents of JAR file

Add Index to JAR file

Description

The jar command is a general-purpose archiving and compression tool, based on ZIP and the ZLIB compression format. However, the jar command was designed mainly to package Java applets or applications into a single archive. When the components of an applet or application (files, images and sounds) are combined into a single archive, they can be downloaded by a Java agent (such as a browser) in a single HTTP transaction, rather than requiring a new connection for each piece. This dramatically improves download times. The jar command also compresses files, which further improves download time. The jar command also allows individual entries in a file to be signed by the applet author so that their origin can be authenticated. A JAR file can be used as a class path entry, whether or not it is compressed.

The syntax for the jar command resembles the syntax for the tar command. It has several operation modes, defined by one of the mandatory operation arguments. Other arguments are either options that modify the behavior of the operation, or operands required to perform the operation.

Operation Arguments

When using the jar command, you have to select an operation to be performed by specifying one of the following operation arguments. You can mix them up with other one-letter options on the command line, but usually the operation argument is the first argument specified.

Create a new JAR archive.

Generate index information for a JAR archive.

List the contents of a JAR archive.

Update a JAR archive.

Extract files from a JAR archive.

Options

Use the following options to customize how the JAR file is created, updated, extracted, or viewed:

Sets the class specified by the entrypoint operand to be the entry point for a standalone Java application bundled into an executable JAR file. The use of this option creates or overrides the Main-Class attribute value in the manifest file. The e option can be used when creating ( c ) or updating ( u ) the JAR file.

For example, the following command creates the Main.jar archive with the Main.class file where the Main-Clas s attribute value in the manifest is set to Main :

The Java Runtime Environment (JRE) can directly call this application by running the following command:

If the entry point class name is in a package, then it could use either the dot (.) or slash (/) as the delimiter. For example, if Main.class is in a package called mydir , then the entry point can be specified in one of the following ways:

Specifying both m and e options together when a particular manifest also contains the Main-Class attribute results in an ambiguous Main-Class specification. The ambiguity leads to an error and the jar command creation or update operation is terminated.

Sets the file specified by the jarfile operand to be the name of the JAR file that is created ( c ), updated ( u ), extracted ( x ) from, or viewed ( t ). Omitting the f option and the jarfile operand instructs the jar command to accept the JAR file name from stdin (for x and t ) or send the JAR file to stdout (for c and u ).

Includes names and values of attributes from the file specified by the manifest operand in the manifest file of the jar command (located in the archive at META-INF/MANIFEST.MF ). The jar command adds the attribute’s name and value to the JAR file unless an entry already exists with the same name, in which case the jar command updates the value of the attribute. The m option can be used when creating ( c ) or updating ( u ) the JAR file.

You can add special-purpose name-value attribute pairs to the manifest that are not contained in the default manifest file. For example, you can add attributes that specify vendor information, release information, package sealing, or to make JAR-bundled applications executable. For examples of using the m option, see Packaging Programs at
http://docs.oracle.com/javase/tutorial/deployment/jar/index.html

Does not create a manifest file entry (for c and u ), or delete a manifest file entry when one exists (for u ). The M option can be used when creating ( c ) or updating ( u ) the JAR file.

When creating ( c ) a JAR file, this option normalizes the archive so that the content is not affected by the packing and unpacking operations of the pack200 (1) command. Without this normalization, the signature of a signed JAR can become invalid.

Generates verbose output to standard output. See Examples.

(Zero) Creates ( c ) or updates ( u ) the JAR file without using ZIP compression.

Читайте также:  Lenovo b50 синий экран при установке windows

When creating ( c ) or updating ( u ) a JAR file, this option temporarily changes the directory while processing files specified by the file operands. Its operation is intended to be similar to the -C option of the tar utility.For example, the following command changes to the classes directory and adds the Bar.class file from that directory to my.jar :

The following command changes to the classes directory and adds to my.jar all files within the classes directory (without creating a classes directory in the JAR file), then changes back to the original directory before changing to the bin directory to add Xyz.class to my.jar .

If classes contained files bar1 and bar2 , then the JAR file will contain the following after running the previous command:

Sets the specified JVM option to be used when the JRE runs the JAR file. JVM options are described on the reference page for the java (1) command. For example, -J-Xms48m sets the startup memory to 48 MB.

Operands

The following operands are recognized by the jar command.

When creating ( c ) or updating ( u ) a JAR file, the file operand defines the path and name of the file or directory that should be added to the archive. When extracting ( x ) or listing the contents ( t ) of a JAR file, the file operand defines the path and name of the file to be extracted or listed. At least one valid file or directory must be specified. Separate multiple file operands with spaces. If the entrypoint, jarfile, or manifest operands are used, the file operands must be specified after them.

When creating ( c ) or updating ( u ) a JAR file, the entrypoint operand defines the name of the class that should be the entry point for a standalone Java application bundled into an executable JAR file. The entrypoint operand must be specified if the e option is present.

Defines the name of the file to be created ( c ), updated ( u ), extracted ( x ), or viewed ( t ). The jarfile operand must be specified if the f option is present. Omitting the f option and the jarfile operand instructs the jar command to accept the JAR file name from stdin (for x and t ) or send the JAR file to stdout (for c and u ).

When indexing ( i ) a JAR file, specify the jarfile operand without the f option.

When creating ( c ) or updating ( u ) a JAR file, the manifest operand defines the preexisting manifest files with names and values of attributes to be included in MANIFEST.MF in the JAR file. The manifest operand must be specified if the f option is present.

To shorten or simplify the jar command, you can specify arguments in a separate text file and pass it to the jar command with the at sign (@) as a prefix. When the jar command encounters an argument beginning with the at sign, it expands the contents of that file into the argument list.

An argument file can include options and arguments of the jar command (except the -J options, because they are passed to the launcher, which does not support argument files). The arguments within a file can be separated by spaces or newline characters. File names within an argument file are relative to the current directory from which you run the jar command, not relative to the location of the argument file. Wild cards, such as the asterisk (*), that might otherwise be expanded by the operating system shell, are not expanded.

The following example, shows how to create a classes.list file with names of files from the current directory output by the find command:

You can then execute the jar command and pass the classes.list file to it using the @arg-file syntax:

An argument file can be specified with a path, but any file names inside the argument file that have relative paths are relative to the current working directory of the jar command, not to the path passed in, for example:

Notes

The e , f , and m options must appear in the same order on the command line as the entrypoint, jarfile, and manifest operands, for example:

Examples

Use the i option when you split the interdependent classes for a stock trade application into three JAR files: main.jar , buy.jar , and sell.jar . If you specify the Class-Path attribute in the main.jar manifest, then you can use the i option to speed up the class loading time for your application:

An INDEX.LIST file is inserted to the META-INF directory. This enables the application class loader to download the specified JAR files when it is searching for classes or resources.

The application class loader uses the information stored in this file for efficient class loading. To copy directories, first compress files in dir1 to stdout , then pipeline and extract from stdin to dir2 (omitting the -f option from both jar commands):

Читайте также:  Проприетарные драйвера nvidia kali linux

jar-The Java Archive Tool

SYNOPSIS

cuxtiv0Mmf Options that control the jar command. jarfile File name of the Jar file to be created ( c ), updated ( u ), extracted ( x ), or have its table of contents viewed ( t ). The -f option and filename jarfile are a pair — if either is present, they must both appear. Note that omitting -f and jarfile accepts jar file from standard input (for x and t) or sends jar file to standard output (for c and u). inputfiles Files or directories separated by spaces, to be combined into jarfile (for c and u), or to be extracted (for x) or listed (for t) from jarfile. All directories are processed recursively. The files are compressed unless option -0 (zero) is used. manifest Pre-existing manifest file whose name : value pairs are to be included in MANIFEST.MF in the jar file. The -m option and filename manifest are a pair — if either is present, they must both appear. The letters m and f must appear in the same order that manifest and jarfile appear. entrypoint The name of the class that set as the application entry point for stand-alone applications bundled into executable jar file. The -e option and entrypoint are a pair — if either is present, they must both appear. The letters m, f and e must appear in the same order that manifest, jarfile, entrypoint appear. -C dir Temporarily changes directories to dir while processing the following inputfiles argument. Multiple -C dir inputfiles sets are allowed. -J option Option passed into the Java runtime environment. (There must be no space between -J and option).

DESCRIPTION

Typical usage to combine files into a jar file is:

In this example, all the class files in the current directory are placed into the file named «myFile.jar». A manifest file entry named META-INF/MANIFEST.MF is automatically generated by the jar tool and is always the first entry in the jar file. The manifest file is the place where any meta-information about the archive is stored as name : value pairs. Refer to the JAR file specification for details about how meta-information is stored in the manifest file.

If you have a pre-existing manifest file whose name : value pairs you want the jar tool to include for the new jar archive, you can specify it using the -m option:

An existing manifest file must end with a new line character. jar does not parse the last line of a manifest file if it does not end with a new line character.

Note: A jar command that specifies cfm on the command line instead of cmf (the order of the -m and -f options are reversed), the jar command line must specify the name of the jar archive first, followed by the name of the manifest file: The manifest is in a text format inspired by RFC822 ASCII format, so it is easy to view and process manifest-file contents.

To extract the files from a jar file, use -x, as in:

To extract only certain files from a jar file, supply their filenames:

Beginning with Java 2 SDK v1.3, the jar utility supports JarIndex, which allows application class loaders to load classes more efficiently from jar files. If an application or applet is bundled into multiple jar files, only the necessary jar files will be downloaded and opened to load classes. This performance optimization is enabled by running jar with the -i option. It will generate package location information for the specified main jar file and all the jar files it depends on, which need to be specified in the Class-Path attribute of the main jar file’s manifest.

In this example, an INDEX.LIST file is inserted into the META-INF directory of main.jar.
The application class loader will use the information stored in this file for efficient class loading. Refer to the JarIndex specification for details about how location information is stored in the index file.

A standard way to copy directories is to first compress files in dir1 to standard out, then extract from standard in to dir2 (omitting f from both jar commands):

Examples of using the jar tool to operate on jar files and jar file manifests are provided below and in the Jar trail of the Java Tutorial.

OPTIONS

generates an INDEX.LIST file in foo.jar which contains location information for each package in foo.jar and all the jar files specified in the Class-Path attribute of foo.jar . See the index example.

f Specifies the file jarfile to be created ( c ), updated ( u ), extracted ( x ), indexed ( i ), or viewed ( t ). The -f option and filename jarfile are a pair — if present, they must both appear. Omitting f and jarfile accepts a «jar file» from standard input (for x and t) or sends the «jar file» to standard output (for c and u). v Generates verbose output to standard output. Examples shown below. 0 (zero) Store without using ZIP compression. M Do not create a manifest file entry (for c and u), or delete a manifest file entry if one exists (for u). m Includes name : value attribute pairs from the specified manifest file manifest in the file at META-INF/MANIFEST.MF. A name : value pair is added unless one already exists with the same name, in which case its value is updated.

Читайте также:  Переименовать администратора windows server 2016

On the command line, the letters m and f must appear in the same order that manifest and jarfile appear. Example use:

You can add special-purpose name : value attribute pairs to the manifest that aren’t contained in the default manifest. For example, you can add attributes specifying vendor information, version information, package sealing, or to make JAR-bundled applications executable. See the JAR Files trail in the Java Tutorial for examples of using the -m option. e Sets entrypoint as the application entry point for stand-alone applications bundled into executable jar file. The use of this option creates or overrides the Main-Class attribute value in the manifest file. This option can be used during creation of jar file or while updating the jar file. This option specifies the application entry point without editing or creating the manifest file.

For example, this command creates Main.jar where the Main-Class attribute value in the manifest is set to Main :

The java runtime can directly invoke this application by running the following command:

If the entrypoint class name is in a package it may use either a dot («.») or slash («/») character as the delimiter. For example, if Main.class is in a package called foo the entry point can be specified in the following ways: or Note: specifying both -m and -e options together when the given manifest also contains the Main-Class attribute results in an ambigous Main.class specification, leading to an error and the jar creation or update operation is aborted.

-C dir Temporarily changes directories ( cd dir) during execution of the jar command while processing the following inputfiles argument. Its operation is intended to be similar to the -C option of the UNIX tar utility. For example: changes to the classes directory and add the bar.class from that directory to foo.jar. The following command, changes to the classes directory and adds to foo.jar all files within the classes directory (without creating a classes directory in the jar file), then changes back to the original directory before changing to the bin directory to add xyz.class to foo.jar. If classes holds files bar1 and bar2 , then here’s what the jar file contains using jar tf foo.jar : -J option Pass option to the Java runtime environment, where option is one of the options described on the reference page for the java application launcher. For example, -J-Xmx48M sets the maximum memory to 48 megabytes. It is a common convention for -J to pass options to the underlying runtime environment.

COMMAND LINE ARGUMENT FILES

An argument file can include options and filenames. The arguments within a file can be space-separated or newline-separated. Filenames within an argument file are relative to the current directory, not relative to the location of the argument file. Wildcards (*) that might otherwise be expanded by the operating system shell are not expanded. Use of the @ character to recursively interpret files is not supported. The -J options are not supported because they are passed to the launcher, which does not support argument files.

When executing jar, pass in the path and name of each argument file with the @ leading character. When jar encounters an argument beginning with the character @ , it expands the contents of that file into the argument list.

For example, you can use a single argument file named classes.list to hold the names of the files:

Then execute the jar command passing in the argfile:

An argument file can be passed in with a path, but any filenames inside the argument file that have relative paths are relative to the current working directory, not the path passed in. Here’s such an example:

EXAMPLES

If you already have separate subdirectories for images, audio files and classes, you can combine them into a single jar file:

To see the entry names in the jarfile, use the «t» option:

To add an index file to the jar file for speeding up class loading, use the -i option.

Оцените статью