Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using Java jdk with Maven and I have the following /etc/environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

# Maven Settings
export JAVA_HOME=/usr/local/jdk1.6.25/
export M2_HOME=/usr/local/apache-maven/apache-maven-3.0.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

The /usr/local/jdk1.6.25 does exist, but when I run mvn -version I get...

Warning: JAVA_HOME environment variable is not set.
Apache Maven 3.0.3 (r1075438; 2011-02-28 17:31:09+0000)
Maven home: /usr/local/apache-maven/apache-maven-3.0.3
Java version: 1.6.0_23, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.0.0-14-generic", arch: "i386", family: "unix"

does anyone know why this does not think my java_home directory is correct even though it exists in my environment file?

share|improve this question
    
you're abusing the /etc/environment file, it should be written in conf format (see the EnvironmentVariables page on help.ubuntu.com), as no shell expansion is available - you're variables will never get evaluated. –  Eliran Malka Jun 16 '13 at 20:29

1 Answer 1

up vote 3 down vote accepted

A couple ideas... First, just to reformat for readability, this is your PATH

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

These are your env vars:

export JAVA_HOME=/usr/local/jdk1.6.25/
export M2_HOME=/usr/local/apache-maven/apache-maven-3.0.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

Note that "java" (the program) is in $JAVA_HOME/bin, not $JAVA_HOME. That will cause a little confusion when a different 'java' is found in the shell's PATH. For example...

$ type java
java is /usr/bin/java

So just modify your PATH:

$ export PATH=$JAVA_HOME/bin:$PATH
$ type java
... should be $JAVA_HOME/bin/java ...

But I don't think that's the issue. From the mvn shell script launcher,

if [ -z "$JAVA_HOME" ] ; then
  echo "Warning: JAVA_HOME environment variable is not set."
fi

This would imply the var really isn't set -- not merely set to a wrong value. Perhaps this is the key hint:

[my java_home ...] even though it exists in my environment file?

Perhaps you added/modified JAVA_HOME to .bashrc or .profile , and then in the same shell tried to run mvn -v ?? If so, these values won't be picked up until you source the file (e.g., . ~/.bashrc ) or create a new login shell (bash -l) in order for these env var's to be set (or reset).

(Also... it's just a matter of opinion, but in your PATH, I'd leave the standard /usr/bin (and /usr/sbin and /bin) in front of any /usr/local/bin or /opt/bin (etc), just to avoid any rouge 'local' programs taking precedence over the standard programs... using something like alternatives would be preferable to override the default versions of standard applications.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.