Question

When I try to run mvn (Apache Maven, that is), I keep getting error "JAVA_HOME" not set.

I follow the instructions to set the JAVA_HOME variable as follow; In the terminal:

user@localhost$export JAVA_HOME=/home/user/jdk1.7.0_02/bin/java

user@localhost$export PATH=$PATH:/home/usr/jdk1.7.0_02/bin

That looks correct, right? Then how come I still getting the incorrect JAVA_HOME error?

Was it helpful?

Solution

JAVA_HOME typically should only include the folder that contains the bin folder.

So in your case

export JAVA_HOME=/home/user/jdk1.7.0_02/

export PATH=$PATH:$JAVA_HOME/bin

In addition for finding the location of your java_home you can follow this command

which java

(This will return the path of the current java binary. Over here its /usr/bin/java)

ls -alh /usr/bin/java

( This will return true path to the symbolic link. Over here its /etc/alternatives/java.

ls -alh /etc/alternatives/java

( This will return true path to this symbolic link which is actual JAVA HOME path)

OTHER TIPS

  1. Goto Terminal and open either of the following files using an editor of your choice (vim, nano, etc):

    # nano /etc/profile
    

    (or)

    # nano /root/.bash_profile
    

    (Instead of root you can also change your normal username.)

  2. Now run the following commands:

    # export JAVA_HOME="/opt/jdk1.6.0"
    # export PATH="/opt/jdk1.6.0/bin:$PATH"
    
  3. Logout and logon the system , now check the java version in your terminal using the following command:

    # java -version
    

    The output should look similar to this:

    # java -version
    java version “1.6.0″
    Java(TM) SE Runtime Environment (build 1.6.0-b105)
    Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
    

No... $JAVA_HOME must point to /home/user/jdk1.7.0_02/

To prevent errors like "/home/user" versus "/home/usr", $PATH should be "$PATH:$JAVA_HOME/bin"

And I recommend using a native package (yum, apt-get, etc).

You could put the following in your .bashrc, then it should be correct even if you change to a different java.

a=`realpath /usr/bin/java`;
export JAVA_HOME="${a%/bin/java}"

Because that's not what you set JAVA_HOME to.

http://maven.apache.org/download.html

Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.5.0_02 and that $JAVA_HOME/bin is in your PATH environment variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top