- How to run .jar file on unix?
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- How to run JAR file on Linux
- How to install JRE on all major Linux distros
- Run JAR file from command line
- Run JAR file from GUI
- Closing Thoughts
- Related Linux Tutorials:
- How to Run .jar File in Ubuntu 22.04 | Linux Mint 21[Beginner’s Guide]
- Step 1: Install Java
- Install OpenJDK Java
- Install Oracle Java
- Step 2: Open / Run .jar file
- Step 3: Create shortcut icon for your .jar application
- Summary:
- How to Run Jar File in Ubuntu Linux
- Run jar files in Ubuntu
- Method 1: Using GUI
- Method 2: Using the Terminal
- Here’s how to set up the JAVA_HOME variable
How to run .jar file on unix?
You must be trying to launch a jar compiled with JDK6, with a local java1.5.
javac -source 1.5 -target 1.5 -bootclasspath /path/to/jre1.5/lib/rt.jar
to check if you can generate 1.5 bytecode compatible.
Have you tried using a newer version of Java on your Unix system?
If you control the jar file, could you target Java 1.5 when it’s compiled?
UnsupportedVersionError means that you have compiled the Java source code with a newer version of Java than what you’re trying to run it with. Java is downwards compatible (newer versions of Java can run Java programs compiled with older versions), but not upwards compatible (older versions of Java cannot run Java programs compiled with newer versions).
You say you’re using Java 5 on Unix. Did you compile it using Java 6 on Windows? Then it’s obviously not going to work.
- Compile your source code using Java 5 on Windows (the safest option)
- Use the compiler flags: -source 1.5 -target 1.5 while you compile (this will not protect you against using Java 6-only classes from the standard library, so this is not a full guarantee that your program will run without errors on Java 5)
- Upgrade to Java 6 on Unix
Recompile your application with Java 5 on your Windows machine.
(Java 6 generates Java 6 compatible byte code by default to use new facilities. The easiest for you is to install a Java 5 JDK and use it to recompile your application)
- Check that JDK or JRE is installed. Install if it is not.
- set JAVA_HOME= # JDK/JRE home directory
- $JAVA_HOME/bin/java -jar file.jar
You should also keep in mind that JVM are not forward compatible, so if you’ve made a jar-file using JDK 1.6, it won’t work with JDK 1.5!
In this case you may either:
- install JDK 1.6 to Unix
- recompile the jar with -target 1.5 flag (but you may get any sort of errors due to API incompatibilities, so the first way is much better)
I faced the same problem. This is because the runtime and compile time JDK versions are different. Make the jar through eclipse after changing the java compiler version. The following link helped me.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
How to run JAR file on Linux
JAR files are those that have been coded and compiled using the Java programming language. In order to run these files on a Linux system, the Java Runtime Environment (JRE) software must be installed first. This is just a software package that allows the system to understand JAR files, and therefore gives it the ability to open and run them. Usually, the JRE package is not installed on most Linux distros by default, so we must first install Java, and then we can open the JAR file(s).
In this tutorial, we will show you how to install the Java Runtime Environment on all major Linux distributions. This will allow you to open JAR files regardless of what Linux distribution you are using. Then, we will use the newly installed software to open JAR files on Linux, via both command line and GUI.
In this tutorial you will learn:
- How to install the JRE on all major Linux distros
- How to open a JAR file via GUI
- How to open a JAR file via command line
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Any Linux distro |
Software | Java JRE |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ – requires given linux commands to be executed as a regular non-privileged user |
How to install JRE on all major Linux distros
The first thing we need to do is install the Java Runtime Environment so that we can open JAR files. You can use the appropriate command below to install the Java JRE with your system’s package manager.
$ sudo apt update $ sudo apt install default-jre
$ sudo dnf install java-latest-openjdk
To install the Java JRE on Arch Linux and Manjaro:
Run JAR file from command line
Running a JAR file from the command line is very simple. We can use the following syntax:
If the JAR file has a GUI component, it will launch on your screen. Otherwise, text will be output to your terminal.
Run JAR file from GUI
- In your file explorer, navigate to the directory where your JAR file is located. If you cannot run the JAR file by simply double clicking on it, then we will need to tell the system to open this file with the Java JRE that we installed earlier.
- Right click on the file and click on ‘Open with other application.’
- From your list of installed applications, choose the Java runtime environment that we installed earlier.
- Our Java program is now running as expected.
Closing Thoughts
In this tutorial, we saw how to run a JAR file on a Linux system. The only trick here is that we first need to install the Java runtime environment, which has varying instructions depending on the Linux distribution you are using. After installation of the JRE software, we are able to run JAR files from both command line and GUI.
Related Linux Tutorials:
Comments and Discussions
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:
- Right-click on the .jar in file manager and go to ‘Properties’ dialog.
- Then, enable ‘Allow executing file as program‘ under Permissions tab.
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:
- Firstly, right-click on blank area in the folder (such as Downloads folder) that contains the .jar file, then select “Open in Terminal”.
- In pop-up terminal dialog, run command to open the .jar file (launch the java app or installer):
/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.
- 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.
- Then, open Home folder and navigate to .local/share/applications/. Create an empty file and re-name to whatever_name.desktop .
- 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
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.
How to Run Jar File in Ubuntu Linux
Downloaded a JAR file and don’t know how to use it? Learn how to run JAR files in Ubuntu based Linux distributions.
If you install any package having the .jar extension and try to execute it, it may throw an error saying «The file is not marked as executable»: And in this tutorial, I will walk you through how you can install its prerequisites and run Jar files in Ubuntu and other Linux with multiple methods.
Run jar files in Ubuntu
If you don’t know, JAR stands for Java ARchive so you must have a working Java environment. If you have Java installed, you should be able to run it. Check if Java is installed with:
If you see an error instead of the version number, install Java runtime environment using the following command:
sudo apt install default-jre
So let’s start with the first one.
Method 1: Using GUI
The first step is to open the file manager from the system menu and navigate to the jar file which you want to run.
Then, right-click on the jar app and select Properties .
From there, select Permissions and enable Allow executing file as program :
That made the file executable.
But you have yet to select which app it should use to run the jar files.
To select an Application to start the jar files, again, click on the jar file and choose the second option Open with Other Application and choose the OpenJDK Java Runtime option:
Now, you can start the jar application like you do with any other files by pressing the Enter key.
In my case, it was an installer and it started as it should:
Method 2: Using the Terminal
If you believe in efficiency, I’m about to show you the terminal method will complete the task in only three commands.
First, open the terminal and navigate to the directory where the jar file is located using the cd command:
Once done, use the chmod command with the +x flag to make the file executable:
And finally, you can use the Java command with the -jar flag to run the jar file:
Here’s how to set up the JAVA_HOME variable
Most of the users set the JAVA_HOME variable incorrectly. So we thought, why not make a dedicated guide to get things done correctly?
I hope you will find this guide helpful.