#AskMe

Install Maven 2 build tool on Windows

If you just start to develop some application, you need some built tools to help to package, compile or make your development structure look right.

Maven is a right tool for that. It’s simple and easy to use, it works with many of programming languages, especially with Java.

Here is simple steps to install maven in your Windows:

Download & Set Environment Variables

Prepare Your home folder

C:\DOCUME~1\[your-user]>mkdir .m2
C:\DOCUME~1\[your-user]>cd .m2
C:\DOCUME~1\[your-user]\.m2>mkdir repository

File: settings.xml

This file is useful for maven to collect all common configuration values that we can do in pom.xml as well. In settings.xml file should not contain specific configuration for some projects but generic for all.

There are two locations where a settings.xml file may live:

I think, you can just use the simple configuration below and put it in ${user.home}/.m2/settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>${user.home}/.m2/repository</localRepository>
  <interactiveMode>true</interactiveMode>
  <usePluginRegistry>false</usePluginRegistry>
  <offline>false</offline>
</settings>

Testing & Maven Commands

Open DOS prompt and test command: mvn -version

D:\Work\develop\opensource>mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 15:44:56+0700)
Maven home: D:\install\apache-maven-3.0.4
Java version: 1.6.0_25, vendor: Sun Microsystems Inc.
Java home: D:\install\java\jdk1.6.0_25\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"

Some commands:

Common Mistakes

 1. When build got error: java.lang.ClassNotFoundException: org.codehaus.classworlds.Launcher

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/classworlds/La
Caused by: java.lang.ClassNotFoundException: org.codehaus.classworlds.Launcher
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.codehaus.classworlds.Launcher.  Program will exit.

Issue & Resolution: