Jar чем открыть linux

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.

jar file not marked as executable

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 :

make file executable using file manager

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:

Running Jar file in Ubuntu with double click

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:

running jar file in Ubuntu

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.

Источник

How can I execute a .jar file from the terminal

I am trying to execute a Minecraft.jar file

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.

Читайте также:  Синхронизация файлов между linux windows

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

  1. Open a command prompt with CTRL + ALT + T
  2. 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»
  3. 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.

Источник

How to Extract JAR Files in Linux

The JAR, also known as the Java Archive, is a compressed file. The file can contain images and relevant class files to reduce the download time. JAR file also archives all the contents related to a file in a single destination.

You can extract the file using the regular platforms like WinRAR or WinZip. Hence, extracting the JAR file is more user-friendly and is easily accessible to people without a high programming knowledge. However, if you are still confused about extracting the JAR files in Linux, this guide will help you extract the JAR files easily in any Linux distro.

How to Extract JAR Files in Linux?

To thoroughly inspect and extract the contents of a JAR file in Linux, execute the following command:

For example, we want to extract the “sample.jar” file in the Downloads directory. We can execute the following commands one by one:

In the previous command, the xvf option represents the following:

  • X option instructs the system about extracting the files from the JAR archive.
  • V option generates the verbose output of the executed command.
  • F option represents the JAR file, in which the system will extract through the command.

If you get the following error, it is essential to install the JDK package in your system. Do it before extracting the file.

In case you don’t want to open the directory in the terminal before extracting the JAR file, run the following command:

You can also extract the JAR files in Linux without using the JAR command. The alternative way to extract these files is by using the “unzip” command to extract the file’s contents. There are no major differences in the usage of these two commands except that the JAR command works specifically only for the JAR files. While you can use the unzip command on similar archived and compressed files. Here is the basic command that you can use for extracting the JAR file:

You can open and access the JAR file from the terminal using the following command:

The components of the JAR file can also be listed by either using the JAR command or using the unzip command. Here are the commands that you can use to list the content:

In the previous command, the “t” option is used for listing the contents available in the JAR file.

Conclusion

The JAR command works specifically only for the files with the “.jar” extension, while the unzip command works for all kinds of zipped files. JAR files were designed as a convenient storage folder for all the related file components and have aided in archiving the important class files related to the functioning of the main file.

We hope this article aids you in comprehending how to extract the JAR files, how to list their components, and how to open the JAR files in Linux by using the different commands. Follow the given steps to extract and list the contents of the JAR files in Linux with no hassle.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.

Источник

Оцените статью
Adblock
detector