0

I have java version 6,7,8 installed on my Ubuntu server, the result of update-alternatives --config java is

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

  Selection    Path                                     Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/jre/bin/java   1081      auto mode
  1            /usr/lib/jvm/java-6-oracle/jre/bin/java   2         manual mode
* 2            /usr/lib/jvm/java-7-oracle/jre/bin/java   1         manual mode
  3            /usr/lib/jvm/java-8-oracle/jre/bin/java   1081      manual mode

I tried How to set the default Java version to set my current java version. when I do java -version I am getting:

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

which is correct but at runtime I getting the version as

Java Home: /usr/lib/jvm/java-6-oracle/jre

which is the result of

System.out.println("Java Home: "+System.getProperty("java.home"))

How do I set java7?

ABC
  • 101
  • 1
    How do you start the Java program that prints the wrong home? Assuming you start it in a terminal somehow, what is $JAVA_HOME in that terminal? – Harald Mar 25 '17 at 17:29
  • Java program is a web application and the statement gets printed after deploying the app in the container and making the request to the resource which contains the print statment. – ABC Mar 25 '17 at 17:36
  • and $JAVA_HOME is set to /usr/lib/jvm/java-7-oracle – ABC Mar 25 '17 at 17:37

1 Answers1

0

Open /etc/environment and manually set the JAVA_HOME Directory.

sudo nano /etc/environment

In your case to set Java 7 add the following line in /etc/environment

JAVA_HOME="/usr/lib/jvm/java-7-oracle/jre"

Then update the source by executing the following command:

source /etc/environment
shahin
  • 101
  • 1
  • I am using bashrc to set the Java home and after setting the Java home here I used source command to reload the changes but no luck – ABC Mar 26 '17 at 08:31
  • Are you trying to run Java from terminal or any third party applications like eclipse?? – shahin Mar 26 '17 at 08:37
  • this http://askubuntu.com/a/154967/201077 resolved my issue – ABC Mar 27 '17 at 06:36