How to Change Java 8 to Java 11 in Linux?


Welcome to the world of Linux, where the jar command plays a pivotal role in managing Java Archive (JAR) files. If you’ve ever wondered, “What does jar command do in Linux?” – you’re in the right place. In this article, we’ll delve deep into the functionalities of the jar command, exploring its features, practical applications, and tips for optimizing your Linux experience.

Understanding the Jar Command

The jar command, a fundamental tool in Linux, serves multiple purposes, primarily revolving around JAR files. These files are essential in Java applications for packaging and distributing classes and resources. Let’s break down the various aspects of the jar command:

Creating JAR Files

To create JAR files using the jar command, use the -cf option followed by the JAR file name and the list of files to include. For example:

jar -cf myapp.jar file1.class file2.class

This command bundles the specified files into a JAR archive named “myapp.jar.”

Extracting JAR Files

You can extract the contents of a JAR file using the -xf option:

jar -xf myapp.jar

This command will extract all the files from “myapp.jar” into the current directory.

Viewing the Contents

To view the contents of a JAR file, use the -tf option:

jar -tf myapp.jar

This command will display a list of all files contained within “myapp.jar.”

Updating JAR Files

The -uf option allows you to update an existing JAR file:

jar -uf myapp.jar newfile.class

You can add new files or update existing ones in the JAR archive.

Verifying JAR Files

To check the integrity of a JAR file, you can use the -vf option:

jar -vf myapp.jar

This command will verify the JAR file for any errors or issues.

Running JAR Files

In Linux, you can execute Java applications packaged in JAR files directly:

java -jar myapp.jar

This simplifies the execution of Java programs, especially those with multiple dependencies.

Advanced Usages

Using Manifest Files

Manifest files provide metadata about the JAR file. You can specify a manifest file when creating a JAR:

jar -cfm myapp.jar manifest.txt file1.class file2.class


The jar command supports compression to reduce file size:

jar -cf myapp.jar -C /path/to/files .

This command compresses the contents of the JAR file while creating it.


Can I include directories when creating a JAR file?

Yes, you can include directories by specifying the directory path when using the jar command.

What is the purpose of a manifest file in a JAR?

A manifest file contains metadata about the JAR file, such as version information and main class details.

How can I extract a specific file from a JAR archive?

You can extract a specific file from a JAR archive by specifying its name after the -xf option.

Are there any GUI tools available for working with JAR files in Linux?

Yes, several GUI tools, such as Ark and File Roller, provide a graphical interface for managing JAR files.

Can I password-protect a JAR file?

The jar command itself does not provide native password protection, but you can use external encryption tools to secure your JAR files.

Is the jar command exclusive to Linux, or can I use it on other operating systems?

The jar command is a part of the Java Development Kit (JDK) and is available on various platforms, including Linux, Windows, and macOS.

How to change version of Java in Linux?

To change the version of Java in Linux, you can update your JAVA_HOME and PATH environment variables to point to the desired Java installation directory for the new version you want to use.

How to change Java 8 to Java 11 in Linux?

To change from Java 8 to Java 11 in Linux, you can update your JAVA_HOME and PATH environment variables to point to the Java 11 installation directory.


In this comprehensive guide, we’ve uncovered the versatility of the jar command in Linux. From creating and extracting JAR files to running Java applications seamlessly, this command is an indispensable tool for developers and system administrators alike. By mastering the jar command, you’ll enhance your Linux experience and streamline your Java development process.

Remember, the jar command is not limited to Linux; it’s an essential component of the Java Development Kit (JDK), ensuring cross-platform compatibility. So, whether you’re a seasoned developer or a Linux enthusiast, harness the power of the jar command to simplify your tasks.

Leave a comment