3

I am trying to get maven installation to work but I am always getting this error

C:\Windows\System32>mvn --version
Error: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:\Program Files\Java\jdk1.7.0_51;"
Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

I know that the error says every thing but I have tried everything here. I have the following setting:

System Variables:

M2_HOME: C:\Program Files\Apache Software Foundation\apache-maven-3.3.3

M2: %M2_HOME%\bin

JAVA_HOME: C:\Program Files\Java\jdk1.7.0_51

I added the whole path maybe it is interested someone. please take a look at the last part.

Path:

C:\Program Files\Java\jdk1.7.0_51\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x86)\git\cmd;%M2%;%JAVA_HOME%\bin;

Path interested part:

%M2%;%JAVA_HOME%\bin;

I have tried it by deleting the %JAVA_HOME%\bin; too but it does not work since I have this path by the SDK installation at the start of the path C:\Program Files\Java\jdk1.7.0_51\bin

I have tried to add the setting to the user variables and it does not work.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
MrPencil
  • 934
  • 8
  • 17
  • 36

4 Answers4

6

JAVA_HOME = "C:\Program Files\Java\jdk1.7.0_51;"

Maven says that there is a semi-colon after the directory name in the JAVA_HOME environment variable. Remove the semi-colon.

Jesper
  • 202,709
  • 46
  • 318
  • 350
  • There is no semi-colon but I had it before. I had just to restart my cmd it works now. ` – MrPencil May 12 '15 at 11:59
  • aye, if you change a system variable, always restart cmd :-) – W vd L May 12 '15 at 12:00
  • @MrPencil Yes, because the command prompt unfortunately doesn't pick up changes to the environment variables immediately - you have to re-open the command prompt. – Jesper May 12 '15 at 12:01
  • Or (at least if you are using bash), you can run the `source` command on your `.bashrc` file to reload the environment variables in that file. – forgivenson May 12 '15 at 12:03
0

you shoud have both maven and java home defined in the same System Variable ...

TubusMan
  • 179
  • 1
  • 1
  • 10
0

Try Rename M2_HOME at MAVEN_HOME Also change M2: %MAVEN_HOME%\bin

0

For me, the trick is to close and open another CMD window, to check if ir worked

Ewerton
  • 4,046
  • 4
  • 30
  • 56