开发者

Installing Maven

I am having trouble getting Maven 3.0.3 to install properly. I have read over Unable to install Maven on Windows: "JAVA_HOME is set to an invalid directory" but none of the answers were able to solve my problem.

This is what I did:

  • Went to http://maven.apache.org/download.html and downloaded apache-maven-3.0.3-bin.zip
  • Extracted files to C:\Program Files, so I now have a directory called apache-maven-3.0.3
  • Went to my system's environment variables and created user variable M2_HOME, value is C:\Program Files\apache-maven-3.0.3\bin
  • JAVA_HOME variable is set properly, can get version from cmd line
  • Edited PATH so the value is now %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseHg\;%JAVA_HOME%;%M2_HOME%

When I go to cmd, I this is what I get:

   D:\>java -开发者_StackOverflowversion
    java version "1.6.0_25"
    Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
    Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)

    D:\>mvn --version
    'mvn' is not recognized as an internal or external command,
    operable program or batch file.

However, if I am actually in the directory I can do the following:

D:\>cd C:\Program Files\apache-maven-3.0.3\bin

D:\>C:

C:\Program Files\apache-maven-3.0.3\bin>mvn --version
Apache Maven 3.0.3 (r1075438; 2011-02-28 11:31:09-0600)
Maven home: C:\Program Files\apache-maven-3.0.3
Java version: 1.6.0_25, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_25\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

Is this how it should actually work? From what I have been told I should not have to be in the directory like that to use any mvn commands. Thank you for your time!


Just keep these two things in mind :

  • Any filesystem path containing whitespaces in between should be surrounded with double quotes. e.g. set M2_HOME="C:\Program Files\apache-maven-3.0.3"
  • PATH should contain the directory in which your executable exists. If M2_HOME is your C:\Program Files\apache-maven-3.0.3, the PATH should be %M2_HOME%\bin


One very simple issue I had is that in Windows you need to close and then reopen CMD after every change to your variables.


I have faced this problem on my 64bit win7 machine and finally fixed when I add another user variable with the name Path and content with %JAVA_HOME%\bin;%M2%. You have Path in System variables but also add in user variable as I described.


http://maven.apache.org/guides/getting-started/windows-prerequisites.html

Maven is written in Java (and primarily used to build Java programs). Thus, the major prerequisite is the Java SDK. You need to install the Java SDK Oracle's download site, and you should install it to a pathname without spaces, such as c:\j2se1.6.

It worked when I changed the location to some other without spaces than C:\Program Files\apache-maven-3.0.3. But on the other computer the location with spaces worked without any troubles.

edited: I meant that on official website, exactly here in Windows' tab, point 2: http://maven.apache.org/download.cgi

2.Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button,then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.2.2.

It is not emphasized to avoid spaces, even they are used in example. I found it confusing so I had a need to write it here. I didn't say a word about Java SDK.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜