2

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
5

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.

  • 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

  • But, what if I have Java JDK and JSE 1.8...? – Btc Sources Apr 28 '15 at 15:27
  • What is **strong text** ? Do I have to put this too like this? – Btc Sources Apr 28 '15 at 15:31
  • Sorry, got rid of that, but wait, you already have java installed based on your question.... What is it that you are trying to do exactly?? Are you trying to run a jar file?? – ryekayo Apr 28 '15 at 15:32
  • Ok, I'm trying that, but are not any solution to have it without having to install it again? I've JSE 8 already... – Btc Sources Apr 28 '15 at 15:34
  • 1
    @ryekayo jar is part of the JDK, it is a developer tool, and shouldn't be part of the runtime (JRE). To use Maven or "a compiler," (even though I don't know what you mean there) wouldn't really solve the issue... – John WH Smith Apr 28 '15 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.