How to: Install Maven on Windows

Well, there's no easily googlable howto on getting started with Maven on a Windows box. And I'm a bit tired of explaining the same thing for so many times, so...

You should have Oracle's JDK set up properly, more on that in a moment.

Here we go, step by step:
1. Grab the latest version of the maven distro from the maven binaries
this, for the time being, is the version 3.0.2

2. Unpack that distro to some convenient public place where you store your development tools.
Something like
would be perfectly fine - short path without any spaces...

3. Then we have to ensure that main maven executable,
is seen in the PATH (so you're able to run it from any other folder)
We do this simply by hitting Win+Pause and switching to the Advanced Tab and hitting Environment Properties:

Then you choose the PATH property (global, not a per-user one), and edit it away as shown:
edit the PATH to enable maven
 Now couple of OKs and you're mostly done, hopefully.

4. Now fire up a command prompt (on most systems this would be win+r cmd <return>).
It should not really matter which current directory you use. Just run the command
mvn -version
this should report something aligned with the version you've downloaded and installed.
This should actually be quite like that my linux maven installation says to me:

anton@arcano:~$ mvn -version
Apache Maven 2.2.1 (rdebian-4)
Java version: 1.6.0_22
Java home: /usr/lib/jvm/java-6-sun-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.35-25-generic" arch: "i386" Family: "unix"

5. Of course, you ask me next - "Okay, so we installed that thing, but how do we use it?"...
Well, don't close the console you've fired in the step #4. Just change the current working dir to the location of your maven project, and fire one or another magical command from the list below:
mvn clean package - do a full clean build of the project, fetching the libraries off the public internet repository, run a basic set of project unit-tests...
mvn dependency:tree - just check which submodules use which libraries
mvn site - generate project documentation
Oh, and note that simple cd command won't switch you across system disks in windows. You need to issue d: command to switch current directory to disk d: and so forth.

No comments: