gautam vegeta
gautam vegeta

Reputation: 653

Error in running java code in ubuntu

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.

Upvotes: 1

Views: 197

Answers (3)

Icarus
Icarus

Reputation: 63956

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.

Upvotes: 0

paulsm4
paulsm4

Reputation: 121649

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

Upvotes: 1

hd1
hd1

Reputation: 34657

Move the source over and recompile on the ubuntu box?

Upvotes: 0

Related Questions