user875921 user875921 - 10 months ago 66
Java Question

error in setting java home environment variables ubuntu

i am new to ubuntu .initially i installed java in Ubuntu.
But i haven't set any envionment variables

After that installed maven build tool to build java package.when i compiled with build tool it shows some error says generic supports after 1.3 packages.

so i realize it JDK runs with 1.3. so i need set java environment variables for latest version

so in my Terminal java -version shows

beeshma@ubuntu:~$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

and i set java environment variables in through below steps

sudo gedit ~/.bashrc

Now go to end of file and add the following lines:

export JAVA_HOME=/path/to/jdk/folder
#usually /usr/java/jdk or /usr/lib/java/jdk
export PATH=$PATH:$JAVA_HOME/bin

Now in terminal type:

sudo source ~/.bashrc

This will make it appear on every terminal if open.

Now you can cross check it by typing following line in terminal

$echo $PATH


What my question when i execute mvn --help
Fallowing error is coming

beeshma@ubuntu:~$ mvn -version
Error: JAVA_HOME is not defined correctly.
**We cannot execute /usr/java/jdk1.7.0_45//bin/java**

Answer Source

Try changing your export to:

export JAVA_HOME=$(/usr/java/jdk1.7.0_45)