简体   繁体   中英

Why does maven ignores the JDK i installed?

When I do anything with Maven (using mvn command) I get the following message:

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 -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)

My JAVA_HOME points at the bin folder of this JDK. My PATH variable also has the same bin folder in it.

My question is what am I doing wrong? Shouldnt java -version say Development kit instead of Runtime enviroment?

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 . Then at the same command prompt, run mvn . This is supposed to echo all commands that the mvn.cmd batch file runs.

  2. Compare the output with the source of the batch file... as installed on your system. 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.)

  3. If that doesn't work, modify the batch file and add a line to echo what %JAVA_CMD% is set to. Then run the modified batch file.

Note that the validation is actually checking that %JAVA_CMD% exists as a file.


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.

Probably you should install package openjdk-8-jdk , but you have only openjdk-8-jre . Thats ubuntu package names. 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 ; rather, set C:\Program Files\...\bin in PATH environment variable.

Also, make sure the path set in JAVA_HOME is one level above the path set in PATH variable.

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.

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. MAven is operational again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM