Java - (Jar|Java ARchive) File

Java Conceptuel Diagram


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 other required resource files:

  • 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.


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.



Jar Archive name follows the coordinate schema.


You can create JAR files, either:

  • by using the JAR utility directly,
  • through an IDE such as Oracle JDeveloper, Eclipse, …
  • or by using a build tool such as the ant utility, maven or gradle.

With the jar command-line utility.

jar cf myPackage.jar *.class


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

Create an Executable Jar

Creating a executable jar file needs more steps:

echo Main-Class: com.gerardnico.HelloWorld>myManifest
md build\jar
jar cfm build\jar\HelloWorld.jar myManifest -C build\classes


  • an executable JAR
java -jar myJAR.jar
java -jar myJAR.jar com.example.main arg1 arg2

Verify / Sign

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


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

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

Search class


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


  • for /R %G in (*.jar) do

    loop over all JAR files in the directory tree, store the file name in %G. See Dos - For Statement

  • @jar -tvf %G |

    - 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.

  • find “ClassName” > NUL

    - 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.

  • && echo %G

    - if ERRORLEVEL is non-zero, write the Java archive file name to standard output (the console). See the AND control opertaor (&&)


  • 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;

Discover More
Gradle - Java

Doc: DSL Doc User guide jar User...
Java Conceptuel Diagram
How to distribute your (Desktop) Java application to your users ?

An article that 1001 ways to bring your application to your users. This page talks especially over Desktop and Command application because Web Application Packaing is dependent of your web framework ?...
Eclipse Main Class
Java - (Main|Start) Class

in Java is called a Main class. The (Main|Start) class is a class that: have a main method will start the main thread (process) main classjar You can start the java application by: calling...
Java Conceptuel Diagram
Java - Application

An application in shipped in an archive format with a main class that contains a main method that starts the application. instancejava/lang/Runtimeclass RuntimeOperating System environment ...
Java Conceptuel Diagram
Java - JRE

Java Runtime Environment (JRE) is a run-time image, which is a complete implementation of the Java SE Platform and contains the runtime executable (mostly the JVM, ie java) in order to run java application....
Eclipse Export Runnable Jar 1
Java - Jar (Startable|Runnable|Executable)

A (Startable|Runnable|Executable) jar-file is an jar archive of compiled classes that contains a manifest-file that point to the (start|main) class You start it with the following command: ...
Java Conceptuel Diagram
Java - Module

A Java module is a packaging format that create a modular JAR file. It's a feature of JDK 9 from the Java Platform Module System (JPMS) that divide the monolithic rt.jar and tools.jar files into 75 distinct...
J2ee Ear Structure
Java - Packaging, Archive, Library (JAR, WAR, EAR File)

For deployment purpose, J2EE applications are delivered and reside in Archive files (or unit). A RAR, WAR or EAR file is a standard JAR (.jar) file with a .war or .ear extension. Each archive extension...
Card Puncher Data Processing
Maven - Shading

Shading is performed by the Apache Maven Shade plugin. Shading = Relocation of the class to avoid a JAR hell Shading i.e. rename - the...

Share this page:
Follow us:
Task Runner