[英]Why does maven ignores the JDK i installed?
When I do anything with Maven (using mvn
command) I get the following message:当我对 Maven (使用
mvn
命令)执行任何操作时,我收到以下消息:
The JAVA_HOME environment variable is not defined correctly This environment variable is needed to run this program NB: JAVA_HOME should point to a JDK not a JRE
JAVA_HOME 环境变量未正确定义 运行此程序需要此环境变量 注意:JAVA_HOME 应指向 JDK 而不是 JRE
java -version
returns the following:返回以下内容:
openjdk version "1.8.0_212-1-ojdkbuild" OpenJDK Runtime Environment (build 1.8.0_212-1-ojdkbuild-b04) OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)
openjdk 版本 "1.8.0_212-1-ojdkbuild" OpenJDK 运行时环境 (build 1.8.0_212-1-ojdkbuild-b04) OpenJDK 64-Bit Server VM (build 25.212-b04, 混合模式)
My JAVA_HOME points at the bin folder of this JDK.我的 JAVA_HOME 指向这个 JDK 的 bin 文件夹。 My PATH variable also has the same bin folder in it.
我的 PATH 变量中也有相同的 bin 文件夹。
My question is what am I doing wrong?我的问题是我做错了什么? Shouldnt
java -version
say Development kit instead of Runtime enviroment? java -version
不应该说开发工具包而不是运行时环境吗?
I don't think we are going to work out what the problem by asking you questions.我不认为我们会通过问你问题来解决问题。 Instead I suggest you do the following:
相反,我建议您执行以下操作:
At the command prompt, set the environment variable %MAVEN_BATCH_ECHO%
to the value on
.在命令提示符处,将环境变量
%MAVEN_BATCH_ECHO%
设置为on
的值。 Then at the same command prompt, run mvn
.然后在同一命令提示符下,运行
mvn
。 This is supposed to echo all commands that the mvn.cmd
batch file runs.这应该回显
mvn.cmd
批处理文件运行的所有命令。
Compare the output with the source of the batch file... as installed on your system.将 output 与系统上安装的批处理文件的源进行比较。 In particular, see what gets echo'd for these lines:
特别是,查看这些行的回显:
@REM ==== START VALIDATION ==== if not "%JAVA_HOME%"=="" goto OkJHome for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i" goto checkJCmd:OkJHome set "JAVACMD=%JAVA_HOME%\bin\java.exe":checkJCmd if exist "%JAVACMD%" goto chkMHome echo The JAVA_HOME environment variable is not defined correctly >&2 echo This environment variable is needed to run this program >&2 echo NB: JAVA_HOME should point to a JDK not a JRE >&2 goto error
(Note that the above excerpt is taken from the most recent version of the Maven batch file does. You may have an older version of Maven that does something different. Check it before jumping to conclusions.) (请注意,上面的摘录取自最新版本的 Maven 批处理文件。您可能有旧版本的 Maven 做一些不同的事情。在下结论之前检查它。)
If that doesn't work, modify the batch file and add a line to echo
what %JAVA_CMD%
is set to.如果这不起作用,请修改批处理文件并添加一行来回显 %
echo
%JAVA_CMD%
设置的内容。 Then run the modified batch file.然后运行修改后的批处理文件。
Note that the validation is actually checking that %JAVA_CMD%
exists as a file.请注意,验证实际上是检查
%JAVA_CMD%
是否作为文件存在。
I see you have actually solved the problem by reinstalling.我看到你实际上已经通过重新安装解决了这个问题。 Unfortunately, that doesn't tell us what the problem really was.
不幸的是,这并不能告诉我们真正的问题是什么。
JAVA_HOME
should refer to folder where bin
folder is located, but I think you have installed inly java, without jdk, run javac -version
you will see if compiler is available. JAVA_HOME
应该是bin
文件夹所在的文件夹,但是我认为你已经安装了java,没有jdk,运行javac -version
你会看到编译器是否可用。
Probably you should install package openjdk-8-jdk
, but you have only openjdk-8-jre
.可能您应该安装 package
openjdk-8-jdk
,但您只有openjdk-8-jre
。 Thats ubuntu package names.那是 ubuntu package 名称。 Name can be different depending on your OS.
名称可能因您的操作系统而异。
It seems you have installed JDK under C:\Program Files\...
and therefore you need to put the absolute path in both, JAVA_HOME
and PATH
environment variables ie do not set %JAVA_HOME%\bin
in PATH
;看来您已经在
C:\Program Files\...
下安装了 JDK,因此您需要将绝对路径放在JAVA_HOME
和PATH
环境变量中,即不要在PATH
中设置%JAVA_HOME%\bin
; rather, set C:\Program Files\...\bin
in PATH
environment variable.而是在
PATH
环境变量中设置C:\Program Files\...\bin
。
Also, make sure the path set in JAVA_HOME
is one level above the path set in PATH
variable.此外,请确保
JAVA_HOME
中设置的路径比PATH
变量中设置的路径高一级。
Last but not the least, make sure you move the path of this JDK above all values under PATH
which will make sure that the path of another JDK does not take precedance over the JDK which you want to work with.最后但并非最不重要的一点是,确保将此 JDK 的路径移动到
PATH
下的所有值之上,这将确保另一个 JDK 的路径不会优先于您要使用的 JDK。
After uninstalling everything and clearing directories and computer restart.卸载所有内容并清除目录并重新启动计算机后。 I reinstalled everything.
我重新安装了所有东西。 In System variables PATH is set to java path + /bin and on JAVA_HOME its just the path to the folder.
在系统变量中,PATH 设置为 java 路径 + /bin,在 JAVA_HOME 上它只是文件夹的路径。 MAven is operational again
MAven 再次运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.