1

I recently installed the open-jdk 7 in my ubuntu server. But the version is still displayed as :

java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.3) (6b24-1.11.3-1ubuntu0.12.04.1)
OpenJDK Server VM (build 20.0-b12, mixed mode)

And if i try to run a java program i get the foll exception :

Exception in thread "main" java.lang.UnsupportedClassVersionError: hello : Unsupported major.minor version 51.0

Which is the consequence of compiling the program with a higher jdk and trying to run in a lower one. How can i correct this.

Edit:But when i do javac -version I get javac 1.7.0_09 as the response.

1
  • There's a javac flag that tells it to compile so it is compatible with lower version. Commented Jan 6, 2013 at 3:57

3 Answers 3

1

It sounds like:

1) You have multiple versions of Java installed (which is perfectly OK to do!) ... and ...

2) "javac" is picking up the correct version ... but "java" is picking up a different version.

SOLUTION:

update-java-alternatives

For example, look at this link:

https://askubuntu.com/questions/64329/how-to-replace-openjdk-6-with-openjdk-7

# EXAMPLE:
$ update-java-alternatives -l
java-1.6.0-openjdk 1061 /usr/lib/jvm/java-1.6.0-openjdk
java-1.7.0-openjdk-amd64 1051 /usr/lib/jvm/java-1.7.0-openjdk-amd64
$ sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Worked like a charm.
0

Move the source over and recompile on the ubuntu box?

1 Comment

I did recompile it again but its not working.And how come my jdk version did not change when I installed open-jdk 7. Dosen't version 51.0 indicate that its complied with jdk 7. But when i do javac -version I get javac 1.7.0_09
0

Probably the newly installed JDK is in another directory that's not part of your $PATH(very common). I would do a find / -name "javac" and see how many entries are found.

You'll probably find more than one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.