How to install jar command in Elementary OS
jar
is part of the JDK. If you installed the JDK correctly, you should have it. As far as I'm concerned, the path to jar
is /usr/lib/jvm/java-7-openjdk-amd64/bin/jar
. The version and architecture are the main variables.
In most cases, the binary should be made available to your shell's PATH
through a few symlinks. For instance, on my Ubuntu machine, jar
is found at /usr/bin/jar
, which is itself a symlink to /etc/alternatives/jar
(another symlink). The final destination is /usr/lib/jvm/java-7-openjdk-amd64/bin/jar
.
It is possible that you may not have these links correctly set up (especially if you don't use the update-alternatives
mechanism), which might make your shell unable to find the jar
executable. The first step to solve this is to locate it. Have a look at the various paths I've given earlier, and try to locate it.
Note: as a last resort, you can use the following find
command to have it looked up system-wide:
$ find / -type f -name "jar"
Once you have found it, make sure the directory in which it lies is within your PATH
.
For instance, let's assume you don't want to create links. If you were to add the /usr/lib/jvm/java-7-openjdk-amd64/bin
directory to your PATH
, you'd add the following to your ~/.bashrc
file:
export PATH="$PATH:/usr/lib/jvm/java-7-openjdk-amd64/bin"
After re-sourcing the file, or reopening your terminal, you should be able to run jar
. Now, if you don't want to use that trick, and prefer to use a symlink, you could do something like...
$ sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/bin/jar /usr/bin/jar
Of course, you'd have to make sure that /usr/bin
is within your PATH
, or you would just end up with the same problem all over again.
You need to run these commands:
sudo apt-get install openjdk-7-jre # to be able to run
sudo apt-get install openjdk-7-jdk # to be able to compile
For Java 8, try this out:
sudo add-apt-repository ppa:webupd8team/java -y
sudo apt-get update
sudo apt-get install oracle-java8-installer
To run a jar file, use this command:
java -jar filename.jar