Jar files in Java

JavaObject Oriented ProgrammingProgramming

JAR is a file format that helps in aggregating Java class file, along with its associated metadata and resources into a single file.

Creation of a JAR file − The jar cf command can be used, where ‘cf’ means creating the file.

jar cf jar_file_name files_to_compress

Once a jar file has been created, a default manifest file is also created. Only one manifest file is present in a specific archive, and it will have the extension ‘mf’ and will be in the pathname. This

manifest file helps give information about the files that have been compressed/present in the package.

Viewing a JAR file − The ‘jar tf’ command can be used to view the file that has been compressed. Here, ‘tf’ represents viewing the table contents.

jar tf jar_file_name

Extracting contents from a jar file − The ‘xf’ command can be used to extract the contents from a jar file. Here, ‘xf’ represents extraction.

jar xf jar_file_name

Updating the jar file − The ‘uf’ command is used to update, where ‘u’ represents updating of contents of an existing jar file. This is done by modifying the manifest file or by adding new files.

jar uf jar_file_name other_input_files

Running a jar file −If an application is compressed as a jar file, the below command can be used.

FILE_LOCATION:\>java –jar file_name.jar
Published on 04-Jul-2020 08:54:20