How to Run .jar File in Ubuntu 22.04 | Linux Mint 21[Beginner’s Guide]

Got a .jar package from web? Here’s a step by step beginner’s guide shows you how to open and create shortcut icons for it in Linux!

File with .jar extension is mostly an application package or installer made by Java programming language. It’s a portable package that can run in Linux, Windows, and macOS within a Java Runtime Environment (JRE).

Step 1: Install Java

As mentioned above, you need Java JRE to run any .jar packages, but Ubuntu Linux does not come with Java pre-installed.

There are 2 Java available: the free and open-source OpenJDK Java, and Oracle Java which is NOT open-source but free for personal and even commercial use. Choose either one that you prefer.

Install OpenJDK Java

OpenJDK is available in system repository, so user can simply search for and install it from Ubuntu Software.

However, Ubuntu Software (aka Snap Store) always leads to Snap package that runs in sandbox! So I would recommend to open terminal by pressing Ctrl+Alt+T on keyboard and run command to install OpenJDK JRE:

sudo apt install default-jre

Install Oracle Java

Oracle Java is not available in Linux repositories. But Oracle offers official packages for Linux for downloading at the link below:

And, beginners can follow this tutorial to install and setup the Java environment in Linux.

Step 2: Open / Run .jar file

After installing Java JRE, you can run the .jar file to directly launch the application or app installer.

Firstly, you need to add executable permission to the .jar file by:

  1. Right-click on the .jar in file manager and go to ‘Properties’ dialog.
  2. Then, enable ‘Allow executing file as program‘ under Permissions tab.
Add Executable Permission to JAR file

Or, simply open terminal and run command to grant executable permission:

chmod u+x /PATH/TO/FILE_NAME.jar

In my case, the command can be chmod u+x ~/Downloads/JPDFViewer.jar.

To open .jar file via OpenJDK, just right-click on it in file manager, and select “Open with Other Application” -> “OpenJDK Java 11 Runtime“.

To open .jar file via Oracle Java, do:

  1. Firstly, right-click on blank area in the folder (such as Downloads folder) that contains the .jar file, then select “Open in Terminal”.
  2. In pop-up terminal dialog, run command to open the .jar file (launch the java app or installer):
    java -jar FILE_NAME.jar
  3. In case you didn’t set Oracle Java as default Java in your Linux. Use command to find out where it’s installed:
    whereis java

    In my case, it’s /usr/lib/jvm/jdk-19/bin/java. So, use the command below to launch .jar app:

    /usr/lib/jvm/jdk-19/bin/java -jar FILE_NAME.jar

Step 3: Create shortcut icon for your .jar application

To make the .jar application visible in system start menu (or search-able in ‘Activities’ overview), you can create a .desktop shortcut file.

  1. Firstly, it’s recommended to move the .jar file into user’s .local/bin folder, so you won’t delete it by accident.TIP: .local is hidden folder, press Ctrl+H to view it in user’s home folder. And, create bin folder if not exist.
  2. Then, open Home folder and navigate to .local/share/applications/. Create an empty file and re-name to whatever_name.desktop.
  3. Edit that .desktop file you just created and add following lines:
    [Desktop Entry]
    Type=Application
    Name=JPDF Viewer
    Comment=A PDF Viewer application written in Java
    Exec=java -jar /home/merilyn/.local/bin/JPDFViewer.jar
    Icon=
    Terminal=false

    Change the value of ‘Name’, ‘Comment’, ‘Exec’, and ‘Icon’ according to what application it is. The value of ‘Exec’ must be correct (change merilyn to your username), or it won’t work!

If you’ve correctly setup the .desktop file, you should be able to launch the .jar application from start menu or ‘Activities’ overview (depends on your DE).

In my case, I left the value of ‘Icon’ empty in the .desktop file, so it shows an universal gear icon instead.

Summary:

In general, file with .jar extension is a Java app or installer. User needs to install either OpenJDK or Oracle Java Runtime Environment for running it.

To create a shortcut icon for the .jar app, just create a .desktop file in user’s .local/share/applications folder with correct rules will do the trick.

Exit mobile version