Java - (Jar|Java ARchive) File

1 - About

JAR stands for Java ARchive and is file format born in 1996 as a simple extension of the popular ZIP archive format with class and others required resource files:

  • manifest
  • signature files
  • images, sounds

The primary motivation for its development was so that Java applets and their requisite components (files, images and sounds) can be downloaded to a browser in a single HTTP transaction, rather than opening a new connection for each piece.

With the advent of the Main-Class manifest header, entire applications can be delivered.

3 - Hell

Jar hell is a term similar to describe all the various ways in which the class loading process can end up not working.

To avoid a Jar hell, the shading technique can be used.

4 - Management

4.1 - Create

With the jar command-line utility.

jar cf myPackage.jar *.class


  • 'c': create new archive.
  • 'f': create a file.

4.2 - Verify / Sign

  • jarsigner: You use the jarsigner tool to sign and verify Java Archive (JAR) files.

4.3 - Verification

jar tf build/libs/building-java-libraries.jar


You should see the required manifest file —MANIFEST.MF— and the compiled class.

4.4 - Search class

4.4.1 - Windows

for /R %G in (*.jar) do @jar -tvf "%G" | find "ClassName" > NUL && echo %G


  • <wrap box>for /R %G in (*.jar) do</note> loop over all JAR files in the directory tree, store the file name in %G. See Dos - For Statement
  • <wrap box>@jar -tvf %G |</note> - run the Java Archive command to list all file names within the given archive, and write the results to standard output; the @ symbol suppresses the echoing of the command to standard output.
  • <wrap box>find “ClassName” > NUL</note> - search standard input, piped from the output of the jar command, for the given class name. It will set ERRORLEVEL to 1 if there's a match (otherwise 0). See DOS - Find Command.
  • <wrap box>&& echo %G</note> - if ERRORLEVEL is non-zero, write the Java archive file name to standard output (the console). See the AND control opertaor (&&)

4.4.2 - Linux

  • below a certain location

find path/to/jars -name "*.jar" -exec grep -Hsli ClassName  {} \;

  • anywhere

for i in $(locate "*.jar");
  do echo $i; jar -tvf $i | grep -Hsi ClassName;

5 - Documentation / Reference

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap