3

I have installed JDK 1.8.0_25 on Mac OS X. It complains when trying to compile Java 8 sources:

  > javac -source 1.8 ComposableList.java
  javac: invalid source release: 1.8

I am sure I am running the compiler from the Java 8 JDK:

  > which javac
  /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/javac
  > java -version
  java version "1.8.0_25"
  Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
  Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

However the javac says it's 1.7

  > javac -version
  javac 1.7.0_60

Could it be that Apple(Oracle?) bundled wrong version of the compiler with the JDK? Or is there something else I am doing wrong?

EDIT: The outcome is the same regardless of whether my $PATH contains any java directories or not (normally it doesn't):

> which java
/usr/bin/java
> which javac
/usr/bin/javac

EDIT 2: One strange thing I found was the reported version of the javac compiler is the same regardless of which compiler I run:

> /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/bin/javac -version
javac 1.7.0_60
> /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/javac -version
javac 1.7.0_60
> /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/javac -version
javac 1.7.0_60

EDIT 3: as @dan suggested, could all javac being symlinks to a single one? Nope, it turned out there are not symlinks:

>ls -l /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/javac
-rwxrwxr-x  1 root  wheel  99376 Sep 17 17:13         /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/javac
> ls -l /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/javac
-rwxrwxr-x  1 root  wheel  99360 Mar 18  2014 /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/javac
Sasha O
  • 3,710
  • 2
  • 35
  • 45
  • What does the command `echo $PATH` say? – damian Nov 10 '14 at 19:33
  • Might be similar to this: http://stackoverflow.com/questions/12757558/installed-java-7-on-mac-os-x-but-terminal-is-still-using-version-6 – michaelok Nov 10 '14 at 19:36
  • 1
    what does `/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/javac --version` says? – njzk2 Nov 10 '14 at 19:38
  • And you might want to check your JAVA_HOME and $PATH ordering. Usually, I do sth like `export PATH=$JAVA_HOME/bin:$PATH` in ~/.[bash_]profile to make sure my environment is sane. – Markus W Mahlberg Nov 10 '14 at 19:43

3 Answers3

1

The solution was in this answer: https://stackoverflow.com/a/22547808/130228 . Turns out, javac executes ~/Library/Java/Extensions/tools.jar if it finds one. So delete ~/Library/Java/Extensions and you'll be fine.

Thanks to https://stackoverflow.com/users/3439760/user3439760 for discovering the answer and to Franco Azabache for finding the link for me.

Community
  • 1
  • 1
Sasha O
  • 3,710
  • 2
  • 35
  • 45
1

I had a tools.jar in: /Library/Java/Extensions once deleting it, javac -version pointed to the JAVA_HOME at that point.

Shahar Hadas
  • 2,641
  • 1
  • 27
  • 29
Olin Blodgett
  • 168
  • 1
  • 8
0

Probably you have a jre/bin directory on the path before the jdk/bin. The javac command does not exist in the jre installation.

dan
  • 13,132
  • 3
  • 38
  • 49
  • There is no separate JRE in Mac OS I am aware of, only JDK – Sasha O Nov 12 '14 at 00:21
  • @SashaO Since you are getting the same version when executing different binaries, can you provide the output of: `ls -la /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/javac` to check if it's not a symlink? If it's not a symlink than something has replaced your binaries. Or somewhere in the path (up to java, eg. /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk is pointing to something else). – dan Nov 12 '14 at 10:51
  • thanks for your suggestion. No, not a symlink -- I have updated the question – Sasha O Nov 12 '14 at 19:01
  • @SashaO Have you checked also all the directories? Maybe `/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home` or something below or above is a symlink. – dan Nov 12 '14 at 19:42
  • not this one either: `find /Library/Java/JavaVirtualMachines -type l` brings nothing but some native libraries – Sasha O Nov 12 '14 at 21:30