问题
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!
回答1:
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"
回答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.
回答3:
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.
回答4:
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
回答5:
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.
回答6:
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.
回答7:
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
来源:https://stackoverflow.com/questions/15392191/configuring-maven-for-windows-7-files-java-jdk1-6-0-23-was-unexpected-at-this