简体   繁体   English

为什么 maven 会忽略我安装的 JDK?

[英]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:相反,我建议您执行以下操作:

  1. 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批处理文件运行的所有命令。

  2. 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 做一些不同的事情。在下结论之前检查它。)

  3. 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_HOMEPATH环境变量中,即不要在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.

相关问题 Maven无法识别在Ubuntu Shell上安装的$ JAVA_HOME jdk - Maven does not recognize the $JAVA_HOME jdk installed on Ubuntu shell 当我安装了Oracle JDK 1.7时,为什么mvn 3.0.4在Ubuntu 13.04上使用-source 1.3? - Why does mvn 3.0.4 use -source 1.3 on Ubuntu 13.04 when I have Oracle JDK 1.7 installed? 为什么 Launch4j 找不到已安装的 JDK? - Why Launch4j does not find installed JDK? 为什么我的 JDK 有问题,即使我用 Unity 安装了它? - Why is there a problem with my JDK even though I installed it with Unity? 为什么 jaxb2-maven-plugin xjc 使用 Corretto jdk11.0.15_9 失败,但使用 Temurin jdk-11.0.14.1+1 失败 - Why does jaxb2-maven-plugin xjc fail with Corretto jdk11.0.15_9 but not with Temurin jdk-11.0.14.1+1 为什么 Maven 在从 Fish 运行时使用错误的 JDK 版本? - Why does Maven use the wrong JDK version when running from Fish? Heroku 忽略system.properties文件,不改变jdk版本 - Heroku ignores system.properties file and does not change jdk version 为什么 maven 忽略我的 JAVA_HOME? - Why maven ignores my JAVA_HOME? Lombok 1.18.2不适用于Maven和JDK 10 - Lombok 1.18.2 does not work with maven and jdk 10 我在Eclipse中安装了Maven Integration,但无法创建Maven POM文件! 为什么? - I installed Maven Integration in the Eclipse but I can't create Maven POM file! Why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM