When I try to run mvn
(Apache Maven, that is), I keep getting error "JAVA_HOME" not set.
当我尝试运行mvn(即Apache Maven)时,我不断地得到错误“JAVA_HOME”而没有设置。
I follow the instructions to set the JAVA_HOME
variable as follow; In the terminal:
我按照说明设置JAVA_HOME变量如下所示;终端:
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?
这是正确的,对吗?那么为什么我仍然得到不正确的JAVA_HOME错误呢?
5 个解决方案
#1
35
JAVA_HOME typically should only include the folder that contains the bin folder.
JAVA_HOME通常只应该包含包含bin文件夹的文件夹。
So in your case
所以在你的情况下
export JAVA_HOME=/home/user/jdk1.7.0_02/
出口JAVA_HOME = / home / user / jdk1.7.0_02 /
export PATH=$PATH:$JAVA_HOME/bin
导出路径= $路径:$ JAVA_HOME / bin
In addition for finding the location of your java_home you can follow this command
除了找到java_home的位置,还可以遵循以下命令
which java
(This will return the path of the current java binary. Over here its /usr/bin/java)
(这将返回当前java二进制文件的路径。这里/usr/bin/java)
ls -alh /usr/bin/java
ls -alh /usr/bin/java
( This will return true path to the symbolic link. Over here its /etc/alternatives/java.
(这将返回到符号链接的真正路径。在这里其/etc/alternatives / java。
ls -alh /etc/alternatives/java
ls -alh /etc/alternatives / java
( This will return true path to this symbolic link which is actual JAVA HOME path)
(这将返回到这个符号链接的真正路径,即实际的JAVA主路径)
#2
3
-
Goto Terminal and open either of the following files using an editor of your choice (vim, nano, etc):
使用您选择的编辑器(vim、nano等)打开以下任一文件:
# nano /etc/profile
(or)
(或)
# nano /root/.bash_profile
(Instead of root you can also change your normal username.)
(你也可以更改你的普通用户名而不是root用户名。)
-
Now run the following commands:
现在运行以下命令:
# export JAVA_HOME="/opt/jdk1.6.0" # export PATH="/opt/jdk1.6.0/bin:$PATH"
-
Logout and logon the system , now check the java version in your terminal using the following command:
登出和登入系统,现在使用以下命令检查您的终端中的java版本:
# 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)
#3
1
No... $JAVA_HOME must point to /home/user/jdk1.7.0_02/
不…$JAVA_HOME必须指向/home/user/jdk1.7.0_02/。
To prevent errors like "/home/user" versus "/home/usr", $PATH should be "$PATH:$JAVA_HOME/bin"
为了防止像“/home/user”和“/home/usr”这样的错误,$PATH应该是“$PATH:$JAVA_HOME/bin”
And I recommend using a native package (yum, apt-get, etc).
我建议使用本机包(yum、apt-get等)。
#4
0
Because that's not what you set JAVA_HOME to.
因为这不是我们设置JAVA_HOME的目的。
http://maven.apache.org/download.html
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.
确保将JAVA_HOME设置为JDK的位置,例如,export JAVA_HOME=/usr/java/jdk1.5.0_02,并且$JAVA_HOME/bin位于PATH环境变量中。
#5
0
You could put the following in your .bashrc, then it should be correct even if you change to a different java.
您可以在.bashrc中放入以下内容,即使您更改为另一个java,它也应该是正确的。
a=`realpath /usr/bin/java`;
export JAVA_HOME="${a%/bin/java}"
#1
35
JAVA_HOME typically should only include the folder that contains the bin folder.
JAVA_HOME通常只应该包含包含bin文件夹的文件夹。
So in your case
所以在你的情况下
export JAVA_HOME=/home/user/jdk1.7.0_02/
出口JAVA_HOME = / home / user / jdk1.7.0_02 /
export PATH=$PATH:$JAVA_HOME/bin
导出路径= $路径:$ JAVA_HOME / bin
In addition for finding the location of your java_home you can follow this command
除了找到java_home的位置,还可以遵循以下命令
which java
(This will return the path of the current java binary. Over here its /usr/bin/java)
(这将返回当前java二进制文件的路径。这里/usr/bin/java)
ls -alh /usr/bin/java
ls -alh /usr/bin/java
( This will return true path to the symbolic link. Over here its /etc/alternatives/java.
(这将返回到符号链接的真正路径。在这里其/etc/alternatives / java。
ls -alh /etc/alternatives/java
ls -alh /etc/alternatives / java
( This will return true path to this symbolic link which is actual JAVA HOME path)
(这将返回到这个符号链接的真正路径,即实际的JAVA主路径)
#2
3
-
Goto Terminal and open either of the following files using an editor of your choice (vim, nano, etc):
使用您选择的编辑器(vim、nano等)打开以下任一文件:
# nano /etc/profile
(or)
(或)
# nano /root/.bash_profile
(Instead of root you can also change your normal username.)
(你也可以更改你的普通用户名而不是root用户名。)
-
Now run the following commands:
现在运行以下命令:
# export JAVA_HOME="/opt/jdk1.6.0" # export PATH="/opt/jdk1.6.0/bin:$PATH"
-
Logout and logon the system , now check the java version in your terminal using the following command:
登出和登入系统,现在使用以下命令检查您的终端中的java版本:
# 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)
#3
1
No... $JAVA_HOME must point to /home/user/jdk1.7.0_02/
不…$JAVA_HOME必须指向/home/user/jdk1.7.0_02/。
To prevent errors like "/home/user" versus "/home/usr", $PATH should be "$PATH:$JAVA_HOME/bin"
为了防止像“/home/user”和“/home/usr”这样的错误,$PATH应该是“$PATH:$JAVA_HOME/bin”
And I recommend using a native package (yum, apt-get, etc).
我建议使用本机包(yum、apt-get等)。
#4
0
Because that's not what you set JAVA_HOME to.
因为这不是我们设置JAVA_HOME的目的。
http://maven.apache.org/download.html
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.
确保将JAVA_HOME设置为JDK的位置,例如,export JAVA_HOME=/usr/java/jdk1.5.0_02,并且$JAVA_HOME/bin位于PATH环境变量中。
#5
0
You could put the following in your .bashrc, then it should be correct even if you change to a different java.
您可以在.bashrc中放入以下内容,即使您更改为另一个java,它也应该是正确的。
a=`realpath /usr/bin/java`;
export JAVA_HOME="${a%/bin/java}"