错误:JAVA_HOME 未正确定义执行 maven [英] Error: JAVA_HOME is not defined correctly executing maven
问题描述
我安装了 java 并设置了路径环境,当我在终端中运行 echo $JAVA_HOME
时,我得到以下输出:
I installed java and set the path environment and when I run echo $JAVA_HOME
in the terminal I get the following output:
/usr/lib/jvm/java-7-oracle/jre/bin/java
我还安装了 apache-maven
并更改了 environment
文件,现在它看起来像这样:
I Also installed apache-maven
and changed environment
file and now it looks like this:
JAVA_HOME="/usr/lib/jvm/java-7-oracle/jre/bin/java"
M2_HOME=/usr/local/apache-maven/apache-maven-3.0.5
M2=$M2_HOME/bin
MAVEN_OPTS="-Xms256m -Xmx512m"
PATH=$M2:$PATH
但是当我执行 mvn --version
时,我收到一个警告:
But when I execute mvn --version
I get a warning:
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-7-oracle/jre/bin/java/bin/java
找不到为什么会重复到最后/bin/java/bin/java
Can not find out why it repeats in the end /bin/java/bin/java
推荐答案
假设您使用 bash shell 并通过 Oracle 安装程序安装了 Java,您可以将以下内容添加到您的 .bash_profile
Assuming you use bash shell and installed Java with the Oracle installer, you could add the following to your .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/jre/bin:$PATH
这将选择 Oracle 安装程序定义的正确 JAVA_HOME
,并首先在您的 $PATH
中设置它,确保找到它.
This would pick the correct JAVA_HOME
as defined by the Oracle installer and will set it first in your $PATH
making sure it is found.
此外,以后更新 Java 时也不需要更改它.
Also, you don't need to change it later when updating Java.
编辑
根据评论:
重新启动后使其持久化
只需在 shell 配置文件中添加这些行.(假设它是 bash
)
Just add those lines in the shell configuration file. (Assuming it's bash
)
例如:.bashrc
、.bash_profile
或 .profile
(对于 ubuntu)
Ex: .bashrc
, .bash_profile
or .profile
(for ubuntu)
使用自定义 Java 安装
将JAVA_HOME
设置为不带$()
的自定义Java安装路径的根文件夹.
Set JAVA_HOME
to the root folder of the custom Java installation path without the $()
.
例如:JAVA_HOME=/opt/java/openjdk
这篇关于错误:JAVA_HOME 未正确定义执行 maven的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!