- How to run .jar file on unix?
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- 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
- Running jar file linux
- How can I execute a .jar file from the terminal
- 9 Answers 9
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.17.43537
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 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.
Running jar file linux
- How to maintain polyglot persistence for microservices Managing microservice data may be difficult without polyglot persistence in place. Examine how the strategy works, its challenges.
- Top developer relations trends for building stronger teams Learn about enterprise trends for optimizing software engineering practices, including developer relations, API use, community .
- 5 noteworthy challenges of automotive software development Modern cars are loaded with technology, but creating in-vehicle applications isn’t always a cakewalk. Here are five unique .
- The basics of implementing an API testing framework With an increasing need for API testing, having an efficient test strategy is a big concern for testers. How can teams evaluate .
- The potential of ChatGPT for software testing ChatGPT can help software testers write tests and plan coverage. How can teams anticipate both AI’s future testing capabilities .
- Retail companies gain DORA metrics ROI from specialist tools DORA metrics and other measures of engineering efficiency are popping up in add-ons to existing DevOps tools. But third-party .
- How to create and manage Amazon EBS snapshots via AWS CLI EBS snapshots are an essential part of any data backup and recovery strategy in EC2-based deployments. Become familiar with how .
- Prices for cloud infrastructure soar 30% Tough macroeconomic conditions as well as high average selling prices for cloud computing and storage servers have forced .
- Deploy a low-latency app with AWS Local Zones in 5 steps Once you decide AWS Local Zones are right for your application, it’s time for deployment. Follow along in this step-by-step video.
- XSS zero-day flaw in Zimbra Collaboration Suite under attack A manual workaround is currently available for a cross-site scripting vulnerability in Zimbra Collaboration Suite, though a patch.
- Rein in cybersecurity tool sprawl with a portfolio approach Market consolidation can counterintuitively exacerbate cybersecurity tool sprawl, with many products offering overlapping .
- Microsoft: Government agencies breached in email attacks While Microsoft mitigated the attacks and found no evidence of further access beyond the email accounts, the Outlook breaches .
- AWS Control Tower aims to simplify multi-account management Many organizations struggle to manage their vast collection of AWS accounts, but Control Tower can help. The service automates .
- Break down the Amazon EKS pricing model There are several important variables within the Amazon EKS pricing model. Dig into the numbers to ensure you deploy the service .
- Compare EKS vs. self-managed Kubernetes on AWS AWS users face a choice when deploying Kubernetes: run it themselves on EC2 or let Amazon do the heavy lifting with EKS. See .
How can I execute a .jar file from the terminal
I know that to execute a file, I use the . command, then the file name with a space between them. But I’m trying to execute a .jar file using the . and it does not work. I went into the properties and marked it as executable and made it run with Java. Is there a way to execute a file with Java in the Bash Terminal? I am trying to execute the Minecraft.jar file.
Hello and welcome, jaorizabal. I slightly corrected your question. Maybe you can install a spell checker for your browser, to improve the next question yourself. Another hint: For text issues, you may mark text with your mouse in the terminal, and then paste it into the edit field of your browser (and elsewhere) with a middle click on the scroll wheel. Then you can layout your code with the buttons at the edit field. This is much faster than taking a screen shot, and uploading it.
9 Answers 9
The . syntax can only be used to run (by «sourcing») shell scripts.
You’ll need to use the java command to run a .jar file:
If you don’t have java installed, you can fix that by installing the default-jre ¹ package. You can see if you already have java installed by running in a terminal:
[1]: This will install the default openjdk Java runtime. You can use openjdk-8-jre , or openjdk-7-jre , or openjdk-6-jre instead, if you prefer — whichever is available on your version of Ubuntu.
Linux is perfectly capable of running a foreign binary, like a JAR file. This is how Wine works, for example. To run JAR files as executable do the following in a console
sudo apt-get install binfmt-support
Cd to your JAR file and change it to executable (you can also do this through file properties in Nautilus)
Run your jar file just as if it was any other binary executable or shell script
Note: Be sure you have binfmt_misc linux kernel module loaded. If you use your custom compiled kernel without this module, binfmt-support won’t work.
Thanks! This is exactly what I was looking for. It’s better than using java -jar because it doesn’t require the host program to know that it is a java program, and it’s better than using a script because you don’t have to worry about passing through STDIN and OUT.
If it is an executable jar, then
Not all jar-Archives contain an executable class, declared to be started in the Manifest file, but if there is, this will work.
Btw.: You don’t start most programs from the shell with the dot. The dot is a shortcut for source , and it only works in the bash and some other shells, to include a script in the scope of the current session.
A compiled binary xybin is simply started with its name if it is in the path:
or, with its absolute path:
or with its relative path:
or if you happen to be in the directory of the file, with this relative path:
The file has to be marked executable for you (see: chmod). All of the above is true for shellscripts too, but they often have an extension .sh, and you can start a shellscript by invoking the interpreter, and then it needn’t be marked executable:
If you don’t want to start a new bash, you can use source, and you do so, to consume function definitions, aliases and variable settings.
You might as well want to make a nice entry for the application in Unity. execute the following commands:
gedit ~/.local/share/applications/minecraft.desktop
In the window that pops up, copy and paste the following:
[Desktop Entry] Type=Application Name=Minecraft Comment=Click here to play Minecraft Exec=java -jar /path/to/minecraft.jar Icon=/path/to/minecraft/icon.png Terminal=false Categories=Game;
You might need to log out and back in to see the effects. 🙂 Also you need to search the internet for a nice lookin Minecraft icon since they don’t provide one with the download..
- Open a command prompt with CTRL + ALT + T
- Go to your «.jar» file directory. If your Ubuntu version / flavour supports it, you should be able to right click on your «.jar» file’s directory and click «Open in Terminal»
- Type the following command:
This way your «.jar» file will execute.
Install jarwrapper. After that (and by adding the executable bit) you can start the jar file just by entering the jarfile name.
sudo apt-get install jarwrapper
This works by using binfmt to add support for a new binary format to the kernel.
java -jar /home/username/.minecraft/launcher.jar
New answer to an old question
Executing a jar file using the regular syntax ./app.jar (instead of java -jar ), is easy to achieve, as explained here: how to create executable jars.
Basically, JAR is a variant of ZIP, which allows random bytes to be pre/appended to the JAR without corrupting it. This means it is possible to prepend a launcher script at the beginning of the jar to make it «executable».
Here is a simple example of turning a «normal» jar into an executable one:
# Append a basic launcher script to the jar cat \ <(echo '#!/bin/sh')\ <(echo 'exec java -jar $0 "$@"')\ <(echo 'exit 0')\ original.jar >executable.jar # Make the new jar executable chmod +x executable.jar
With this, you can now run ./executable.jar instead of java -jar original.jar . This works on all unix like systems including Linux, MacOS, Cygwin, and Windows Linux subsystem.