错误:未正确定义JAVA_HOME正在执行maven [英] Error: JAVA_HOME is not defined correctly executing maven
问题描述
我安装了java并设置了环境路径,当我执行 echo $ JAVA_HOME
时,我得到以下输出:
I installed java and set path to environment and when I execute echo $JAVA_HOME
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
这将选择正确的 JAVA_HOME
为由Oracle安装程序定义并将其首先设置在 $ 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.
编辑
根据评论:
重启后使其持久
Making it persistent after a reboot
只需在shell配置文件中添加这些行。 (假设它是 bash
)
Just add those lines in the shell configuration file. (Assuming it's bash
)
Ex: .bashrc
, .bash_profile
或 .profile
(对于ubuntu)
Ex: .bashrc
, .bash_profile
or .profile
(for ubuntu)
使用自定义Java安装
Using a custom Java installation
设置 JAVA_HOME
到没有 $()
的自定义Java安装路径的根文件夹。
Set JAVA_HOME
to the root folder of the custom Java installation path without the $()
.
Ex: JAVA_HOME = / opt / java / openjdk
这篇关于错误:未正确定义JAVA_HOME正在执行maven的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!