My current java version running on my Ubuntu 14.04 is
java -version
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)
sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode
* 1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
2 /usr/lib/jvm/java-7-oracle/jre/bin/java 1 manual mode
Press enter to keep the current choice[*], or type selection number: 1
test@test-ZX-530:/media/test/SSD/N7$ sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-7-openjdk-amd64/bin/javac 1071 auto mode
* 1 /usr/lib/jvm/java-7-openjdk-amd64/bin/javac 1071 manual mode
2 /usr/lib/jvm/java-7-oracle/bin/javac 1 manual mode
Press enter to keep the current choice[*], or type selection number: 1
============================================
Checking build tools versions...
************************************************************
You asked for an OpenJDK 7 build but your version is
java version "1.7.0_72" Java(TM) SE Runtime Environment (build 1.7.0_72-b14) Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode).
************************************************************
build/core/main.mk:191: *** stop. Stop.
#### make failed to build some targets ####
. build/envsetup.sh
lunch aosp_flo-userdebug
lunch aosp_flo-userdebug
Building Kitkat needs Sun/Oracle JDK 6 version, and building Lollipop needs OpenJDK 7. Currently, I have both projects on my Ubuntu. I use a script to switch the JDK version, and it works.
Put the jdk_switch.sh in my ~ directory and run the following commands to switch jdk version:
$ . ./jdk_switch.sh jdk7
$ . ./jdk_switch.sh jdk6
The path of JDK are:
/usr/lib/jvm/java-6-oracle/
/usr/lib/jvm/java-7-openjdk-amd64/
The content of jdk_switch.sh:
#!/bin/bash
case $1 in
jdk6)
export JAVA_HOME=/usr/lib/jvm/java-6-oracle/
;;
jdk7)
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
;;
*)
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
;;
esac
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
java -version
OpenJDK 7 version is :
java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
In your case, exporting your PATH and CLASSPATH might helpful. Or just use a simple bash script. I hope this might help you.