3

I'm having trouble using eclipse/intelliJ because whenever I try to check java version, this is what I will get. But java is present in the system preferences pane.

$ java -version
Unable to locate an executable at "/usr/libexec/java_home/bin/java" (-1)
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
bengalurean
  • 69
  • 1
  • 3
  • 10

4 Answers4

7

If you're on Mac, do this:

export JAVA_HOME=$(/usr/libexec/java_home)

or:

export JAVA_HOME=`/usr/libexec/java_home`

Instead of this:

export JAVA_HOME=/usr/libexec/java_home

or:

export JAVA_HOME="/usr/libexec/java_home"
matthew
  • 2,156
  • 5
  • 22
  • 38
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
1

Looks like java is installed but classpath is not set. please try following command in terminal to set the java path.

export JAVA_HOME=/usr/libexec/java_home/bin/java
export PATH=$JAVA_HOME/bin:$PATH

Once this is done then check the java version. Hope it helps.

Vaibhav Jain
  • 1,939
  • 26
  • 36
  • Hello Vaibhav, when I tried doing this, it says this: Last login: Mon May 2 16:57:40 on ttys000 $ export JAVA_HOME=/usr/libexec/java_home/bin/java $ export PATH=$JAVA_HOME/bin:$PATH $ java -version java version "1.6.0_65" Java(TM) SE Runtime Environment (build 1.6.0_65-b14-468-11M4833) Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-468, mixed mode) But when I try again to "Java -version" I get this error Unable to locate an executable at "/usr/libexec/java_home/bin/java" (-1) – bengalurean May 02 '16 at 15:01
  • Can you please open a new terminal and execute above two lines separately. – Vaibhav Jain May 02 '16 at 15:30
0

Check that java 8 is in your PATH or whatever it is called on windows if you are using windows.

If that's not the problem, consider uninstall and install again java, something might have gone wrong back when you installed it.

It none of this works, could you show us your intelliJ or eclipse settings about Java location ?

derOtterDieb
  • 545
  • 4
  • 12
  • 35
  • I agree, I tried going back to default version of java that ships with OSX. Hope I can resolve this. – bengalurean May 02 '16 at 15:05
  • From what I can read to the answer you gave to @Vaibhav Jain just above, the version currently used by your system is 1.6. That's your problem I guess. – derOtterDieb May 02 '16 at 15:08
  • Yes! I downloaded jdk 1.8 and changed the JDK settings in project structure in IntelliJ and it worked. – bengalurean May 02 '16 at 15:19
-1

I can now run my java programme in IntelliJ Idea.

May be one day I will do the same by helping somebody out.

Solution was:

First I would like to give a context. I had deleted 'Java' folder under

/HDD/library/

On my mac, because I was trying to uninstall all legacy versions of Java. Then on Oracle site, I read that I should have kept default (java 1.6) to facilitate Eclipse installation.

Then:

  1. downloaded java 1.6 on apple website - https://support.apple.com/kb/DL1572?locale=en_US

  2. used @vaibhav Jain's solution to set/point to my jdk folder instead of default one. By using this:

    export JAVA_HOME=/usr/libexec/java_home/bin/java
    export PATH=$JAVA_HOME/bin:$PATH
    
  3. Dowloaded jdk 1.8 from Oracle website to update my java - http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

  4. Tried checking the java version on terminal by $ java -version

  5. Confirmed that it was showing the updated version.

  6. Tried running java programs, and I was able to without any error messages!

bengalurean
  • 69
  • 1
  • 3
  • 10