zcourts
zcourts

Reputation: 5041

windows 7 maven 2 install

I'm about to work through a book, "Flex on Java" and it's asked me to install maven 2+ i downloaded maven from the apache site. Added :

M2_HOME = C:\apache-maven-2.2.1

and

M2 = %M2_HOME%\bin

to the environment vars according to the instructions at http://maven.apache.org/download.html then it gets to number 6 which says "In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line."

Which environment variable should i edit and add %M2% to?

After googling i found a post which says "append", not prepend to the value of JAVA_HOME I've tried prepending and appending it to the java home var but when i try to do an mvn command from the command line it says its not recognised.

Never used maven before so this is my first set up. Can anyone see what i'm not doing right or what else i need to do to be able to use the mvn command, please and thank you.

Upvotes: 11

Views: 62760

Answers (9)

AKT
AKT

Reputation: 172

Download Maven.
Extract it in your directory say :C:\Program Files\apache-maven-3.2.5
Set its path: go to => Control Panel -> System -> Advanced system settings -> Advanced Tab -> Environment Variables -> The path variable is right on the *system variable*s area
Click 'New'
Variable name: M2_HOME
VAriable value: C:\Program Files\apache-maven-3.2.5
Click 'ok'

Append '%M2_HOME%\bin;' to path variable.

Restart your system, CMD=> mvn -v

Upvotes: 0

jean d'arme
jean d'arme

Reputation: 4353

When entering PATH variable "prepending" means to put it before Java path so it will look like this:

%M2%;C:\Program Files (x86)\Java\jdk1.7.0_51\bin

Upvotes: 0

Flashmac
Flashmac

Reputation: 1

Some people forget that if you already have a command line window open whilst your setting the Env Vars then there is a good chance you will continue to view errors.

Once you have set the vars, try opening a new command line window ;)

Upvotes: 0

Growling Flea
Growling Flea

Reputation: 129

I tried following the above advice and I still had issues getting the mvn --version to run. I searched on line and I found a similar site that gave the following advice.

"Please run the command SET in a command window and paste the relevant parts here, i.e. M2_HOME, M2, JAVA_HOME and PATH."

The instructions on the Apache site weren't very clear so I will reattempt to make is obvious, even to the most casual of observers.

1) Go to the advanced settings. The shortcut is the windows + pause.

2) In Win7, click on Advanced System Settings. This will open up a System Properties Box

3) On the advanced tab, click on Environment Variables.

4) Under the Environment Variables there are two areas: User Variables and System Variables. When you click on edit, they both have the same box. As discussed here and on the site, we need enter paths and variable names so Windows will automatically check your Java / Maven area when you enter in Maven commands. Since I had trouble I put the Java variables (JAVA_HOME), the Maven Variables (M2 and M2_HOME), the paths (these are unique to your machine) in both User Variables and in System Variables.

5) If this still does not work, you have to open a command line and type the following: "SET M2_HOME". After typing 'SET M2_HOME' you should see some activity. If you don't, you have made a typing mistake or you are not typing in the correct paths. If you see activity, type SET M2. Then follow up by typing SET JAVA_HOME and SET PATH.

If you see activity after typing each of the SET commands you should be able to get the 'mvn --version' command to work.

This worked for me. I hope it works for you. Good luck.

Upvotes: 0

user2217691
user2217691

Reputation: 1

I had this same issues when installing Maven. But you do not have to add any System variables. Follow the instructions and add all necessary User variables, including a new "Path" variable.

Ignore that it does not look to be working and run mvn --version from cmd and it works.

Upvotes: 0

Tabcina
Tabcina

Reputation: 75

It is strange because JAVA_HOME is perfectly picked as a USER variable whereas on Windows7 mvn is not properly installed unless its variables (both %M2% and %M2_HOME%) are set as SYSTEM variables. I can't explain the rationale behind it but its a workaround.

Upvotes: 1

babinik
babinik

Reputation: 648

Had the same issue. As mentioned Dave and Nic M2_HOME and M2 should be added to the System variables.

Upvotes: 4

MoienGK
MoienGK

Reputation: 4654

for further information and future googlers : i just tried to run maven , so i added the M2_HOME to "user variables" but the system failed to recognize mvn --version command, so i added M2_HOME to System Variables and it solved the problem (the apache told us to add the M2_HOME in user variables)

Upvotes: 11

Jose Diaz
Jose Diaz

Reputation: 5398

The environment variable you should edit is path.

The route on Windows 7 is:

Control Panel -> System -> Advanced system settings -> Advanced Tab -> Environment Variables -> The path variable is right on the system variables area

The path variable specifies a group of directories and/or paths that Windows searches for commands definitions. You should append to the end of this variable value the value ;%M2% (note the semi-colon, different paths should be separated by them) in order for Windows to be able to find the Maven command definitions.

Appending ;%M2 at the end of the path environment variables is the same as appending ;C:\apache-maven-2.2.1\bin

To test that everything is ok, type mvn --version, if everything is right then the current Maven version you're using should be displayed on the screen.

Upvotes: 24

Related Questions