22

I am trying to configure Maven on my Win 7 machine. I am following these steps: http://maven.apache.org/download.cgi I downloaded Maven into folder c:\Program Files\Apache Software Foundation\apache-maven-3.0.5\

I set all environmental variables as described in the URL above

JAVA_HOME = C:\Program Files\Java\jdk1.6.0_23
M2_HOME = c:\Program Files\Apache Software Foundation\apache-maven-3.0.5\
M2 = %M2_HOME%\bin
PATH = %M2%; C:\Program Files (x86)\SSH Communications Security\SSH Secure Shell;     %JAVA_HOME%\bin ; C:\Program Files\Java\jdk1.6.0_23

But when I enter: C:\Users\Andrei>mvn --version

I get a :

Files\Java\jdk1.6.0_23"" was unexpected at this time.

Can you please help me with this issue? Let me know please if you need more details. Thanks in advance!

Andrei
  • 801
  • 2
  • 10
  • 27

7 Answers7

44

This one solved it for me: http://www.xinotes.net/notes/note/559/

It is a problem with how the JAVA_HOME path is being set.

Set the path without quotes like this:

set java_home=c:\Program Files\Java

Or using the 8 char syntax for folder names like this:

set java_home="c:\Progra~1\Java"
Darwin von Corax
  • 5,201
  • 3
  • 17
  • 28
JHP
  • 998
  • 1
  • 10
  • 8
  • 2
    Similarly, if you M2_HOME has quotes e.g. M2_HOME="C:\Program Files (x86)\Apache Software Foundation\apache-maven-3.0.5" then you will get the error: Files was unexpected at this time." – Leo Aug 02 '13 at 02:53
  • 2
    I was getting the "unexpected file" error and I sorted the issue with the link provided - it changed to **xinotes.net** Maven does not like that the Windows variables are between double quotes with spaces: This works: C:\Progra~2\Java\jdk1.7.0_79\ This doesn't: "C:\Program Files (x86)\Java\jdk1.7.0_79" – cbaldan May 27 '15 at 18:23
  • @Cbaldan Thank you so much, man! That is such a stupid fix haha – flakes Jul 25 '15 at 19:57
2

To solve the same issue

I did:

SET M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.2.3-bin\apache-maven-3.2.3

Then

SET JAVA_HOME=C:\Program Files (x86)\Java\jre7

And finally I added to the beginning of Path

SET Path=%JAVA_HOME%\bin;%M2_HOME%\bin;...

After exiting all my running cmd.exe and opened a new one I was able to do mvn --version with no problems.

ThelmaJay
  • 165
  • 1
  • 3
  • 9
1

I had the same problem, but the cause was M2_HOME variable defined as:

C:\apache-maven-3.2.2\bin

instead of

C:\apache-maven-3.2.2\

Also the JAVA_HOME should be to the java folder, and not to the \bin sub-folder.

Lior Bar-On
  • 10,784
  • 5
  • 34
  • 46
1

I ran into a similar issue and the problem is with the presence of character "(" in the current directory path where maven is being run eg:- C:\Work(test)\Java-Project. I simply changed it to C:\Work\Java-Project and its working fine now.

For info I'm running Windows 10 with Maven V3.6.0

Ganesh Pendyala
  • 371
  • 4
  • 7
0

Insert with windows GUI Environment Variable Configurations > System Variables : Name JAVA_HOME Path C:\Program Files (x86)\Java\jre7\ << with "\" in the end. no quotes.

kill process cmd.exe and re-open if it was opened. It worked to me.

0

I had the same issue. I didn't have quotes around the values for M2_HOME or JAVA_HOME, but still got the error.

I moved %M2_HOME%\bin and %JAVA_HOME%\bin left in the path so that both occurred before any spaces in the path and the problem vanished.

0

Error Message : was unexpected at this time when I run mvn --version command in cmd.

Please find the procedure:

My Computer -> Right click properties-> Advanced-Environment Variables- User Variable

Maven 3.2.3

User Variable :
Variable name :M2 
Variable Value : %M2_HOME%\bin
Variable name : M2_HOME
Variable Value :  C:\WLS1033\Apache Software Foundation\apache-maven-3.2.3
Variable name :path 
Variable Value : %M2_HOME%\bin

Result :

D:\Documents and Settings\x169810>mvn --version
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T16:58:10-04:00)
Maven home: C:\WLS1033\Apache Software Foundation\apache-maven-3.2.3
Java version: 1.6.0_18, vendor: Sun Microsystems Inc.
Java home: C:\WLS1033\jdk160_18\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"

My Computer -> Right click properties-> Advanced-Environment Variables- User Variable

Maven 1.0.2

User Variable :
Variable name :M2 
Variable Value : %MAVEN_HOME%\bin
Variable name : MAVEN_HOME
Variable Value :  C:\WLS1033\Apache Software Foundation\maven-1.0.2
Variable name :path 
Variable Value : %MAVEN_HOME%\bin
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Anil
  • 1