mvn : JAVA_HOME / M2_HOME not found in your environment.

Just got a new Windows 8.1 box, and needed to re-download Maven for some projects I'm working on. After going through the configuration setup instructions they provided, I gave "mvn --version" a whirl in the command prompt, and was greeted by the well-known "'mvn' is not recognized as an internal or external command, operable program or batch file" message. This was remedied by finding where I extracted Maven to (typically "C:\Program Files\Apache Software Foundation\apache-maven-3.x.y"), and renaming bin\mvn.cmd to bin\mvn.bat.

Voila, mvn is now recognized! However, this only resulted in yet another error message:


"Error: JAVA_HOME not found in your environment. Please set the JAVA_HOME variable in your environment to match the location of your Java installation."

I at first tried to manually add this variable to my system environment variables, but that was leading down a dead-end.

Instead, the real solution lies in altering a tiny piece of the batch script. Find the line that says "if exist "%M2_HOME%\bin\mvn.cmd" goto init" (around line 100) and change that file to match the new filename we just set: \bin\mvn.bat.

Comments

Popular Posts