4

I'm using Elementary OS, and just found I've not jar command. I tried to install it through the "typical":

apt-get install jar

But this doesn't work, since "jar" is not found in the repositories or isn't the name of the package.

I've tried to look for it in google, but jar is such an used word that I've found nothing useful.

Could you say me how to install it?

Thank you in advance

Update:

$ java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) Client VM (build 25.40-b25, mixed mode)

$ javac -version
javac 1.8.0_40
Btc Sources
  • 147
  • 1
  • 1
  • 9

2 Answers2

8

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.

John WH Smith
  • 15,880
  • I just found the /usr/lib/jvm/jdk1.8.0_40/bin/jar before reading your answer. Of course things seems to be as you say, I'm going to do it and report news. – Btc Sources Apr 28 '15 at 15:58
  • /usr/lib/jvm/jdk1.8.0_40/bin isn't part of your PATH. I'd suggest creating a link from /usr/bin/jar to /usr/lib/jvm/jdk1.8.0_40/bin/jar (see the end of my answer). – John WH Smith Apr 28 '15 at 16:04
  • Yeah I know, I just did that. Thanks John. – Btc Sources Apr 28 '15 at 16:08
3

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

ryekayo
  • 4,763