Sunday, September 25, 2011

Maven 2 and 3 on the Same Windows Install

 

This is my first post! Forget the long-winded "welcome to my blog", let's get down to business.

Setting Up Maven 2 and 3 on the Same Machine

Requirements at work dictated I needed to set up my local machine to run both versions of Maven at the same time. Here is how to do this:

Step 1: Install Maven 2 and 3

I installed Maven 2 in C:\mvn and Maven 3.0.3 in C:\mvn3, using short names for easy memory.

Both can be downloaded at http://maven.apache.org/download.html.

Step 2: Rename Maven 3 Files

The problem in using both Maven 2 and 3 from command line is that they both have the same batch file name, executable file name, and use the same environment variables.

To remedy this, we need to swap all shared variable and file names in Maven 3 so that there are no collisions.

1) Rename [path to maven 3]/bin/mvn to mvn3.
2) Rename [path to maven 3]/bin/mvn.bat to mvn3.bat

Step 3: Replace variables in mvn3.bat

To set up your mvn3.bat, simply open it in a text editor and make the following replacements:

"M2_HOME" -> "M3_HOME"
"mvn.bat" -> "mvn3.bat"

Step 4: Environment Variables

Now you simply need to:

1) Add both maven 2's bin directory and maven 3's bin directory to your system PATH.
2) Add M2_HOME and M3_HOME to your system path, making sure they point to the different installation locations for both versions.

Finished!

There we go! Restart your command prompt / Cygwin and "mvn" will now run Maven 2 and "mvn3" will now run Maven 3.

Thanks to Shaun Husain for setting me on the right track with this process.

No comments:

Post a Comment