2

I'm very new to Ubuntu, so I would appreciate some help.

I am installing Apache ActiveMQ, and for this I need maven to be installed. First I installed jdk and jre java packages, and edited /etc/profile like the following:

JAVA_HOME=/usr/local/java/jdk1.7.0_09 
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin 
JRE_HOME=/usr/local/java/jre1.7.0_09 
PATH=$PATH:$HOME/bin:$JRE_HOME/bin 
export JAVA_HOME 
export JRE_HOME 
export PATH

but when I installed maven, and it gave me JAVA_HOME is not defined correctly. So after a small research, I edited /etc/bash.bashrc and included the following:

JAVA_HOME=/usr/local/java/jdk1.7.0_09 
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin 
export PATH 

And now it displays:

Error: JAVA_HOME is not defined correctly.
  We cannot execute /usr/local/java/jdk1.7.0_0.9/bin/java/bin/java

I'm sure my mistake is trivial, but it's the first time I use ubuntu So I couldn't figure it out... I appreciate any help

user1793538
  • 23
  • 1
  • 1
  • 4
  • 1
    i think duplicate of http://stackoverflow.com/a/11021053 – Sathish Nov 15 '12 at 09:41
  • I had the same problem and the solution was this [mkyong](http://www.mkyong.com/java/maven-java_home-is-not-defined-correctly-on-mac-osx/) – OJVM Dec 23 '14 at 16:36

2 Answers2

0

In my case, the error was due to the carriage return character being appended to the file where the JAVA_HOME variable was declared making the error harder to track down:

cat -A /etc/environment 

The output:

JAVA_HOME=/usr/java/jdk1.6.0_25^M$
TOMCAT_HOME=/usr/tomcat7^M$
M2_HOME=/usr/maven

The fix:

perl -pi -e "s/\015//g" /etc/environment
Saïd
  • 8,780
  • 1
  • 28
  • 28
-1

It's clearly mentioning we cannot execute /usr/local/java/jdk1.7.0_0.9/bin/java/bin/java

This path indeed doesn't exist. If you have downloaded zip distribution of JDK 1.7 point your path to extracted Java folder bin directory.

If you are already able to run java from bash, just type which java, that should print the installed folder

RaceBase
  • 18,428
  • 47
  • 141
  • 202
  • Hi @Nitin... thx for reply. Actually the path to the extracted java folder is /usr/local/java/jdk1.7.0_09, and the bin directory is inside it. Ain't my code valid in this case? – user1793538 Nov 15 '12 at 13:50
  • i think this is great http://stackoverflow.com/questions/11019231/error-java-home-is-not-defined-correctly-in-building-jikes-rvm/11021053#11021053 – RaceBase Nov 16 '12 at 06:27
  • Thx @Nitin... the problem is solved... it turned out that I had misconfigured a different file... – user1793538 Nov 16 '12 at 18:32
  • 1
    @user1793538 - please mention the name of the file if you remember. It will help other people. – stack1 Mar 08 '15 at 18:47