Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolving version conflict between java and javac on Ubuntu

Tags:

I have a problem with my compiled Java application on Ubuntu. It throws UnsupportedClassVersionError. I am compiling with a higher JDK version than the one that is configured in my PATH to run Java:

$ javac -version
javac 1.7.0_147

$ java -version
java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.2)
OpenJDK Client VM (build 20.0-b11, mixed mode, sharing)

How can I resolve this?

like image 258
xralf Avatar asked May 14 '12 14:05

xralf


People also ask

Why javac is not working in Ubuntu?

It means that javac.exe executable file, which exists in bin directory of JDK installation folder is not added to PATH environment variable. You need to add JAVA_HOME/bin folder in your machine's PATH to solve this error. You cannot compile and run Java program until your add Java into your system's PATH variable.

What is the difference between Java version and javac version?

The javac command is used to compile Java programs, it takes . java file as input and produces bytecode. Following is the syntax of this command. The java command is used to execute the bytecode of java.

How do I switch between two Java versions in Ubuntu?

To switch between installed java versions, use the update-java-alternatives command. ... where /path/to/java/version is one of those listed by the previous command (e.g. /usr/lib/jvm/java-7-openjdk-amd64 ).


1 Answers

Type following command in terminal :

  sudo update-alternatives --config java

It will ask you for:

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection      Path                                            Priority   Status

    0           /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      auto mode

    1           /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode

    2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java  1051      manual mode


  Press enter to keep the current choice[*], or type selection number:

I enter 2 as I want to use java 1.7.0_21

like image 144
Ruju Avatar answered Sep 28 '22 21:09

Ruju