Monday, January 17, 2011

Updating to Maven 3.0.2 in Mac OS X Snow Leopard

Mac OS X 10.6.6 ships with Maven 2.2.0 installed. Invoking Maven from the Terminal with the mvn -v command produces the following output:
  bash-3.2# mvn -v
  Apache Maven 2.2.0 (r788681; 2009-06-26 06:04:01-0700)
  Java version: 1.6.0_22
  Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  Default locale: en_US, platform encoding: MacRoman
  OS name: "mac os x" version: "10.6.6" arch: "i386" Family: "mac"
To manually upgrade to Maven 3.0.2, complete these 3 steps:
  1. Download Maven 3 archive
  2. Unpack archive into /usr/share/java/
  3. Link /usr/share/maven to /usr/share/java/apache-maven-3.0.2
Below are the details of each step.


1. Download Maven 3 archive
Go to the Maven download site and download the file named “apache-maven-3.0.2-bin.tar.gz” to your Desktop.


2. Unpack archive into /usr/share/java/
Open the Terminal. You will need root access to install Maven. Type the following to open a root shell:
  sudo bash
Type your administrator password if prompted. Copy the file that you downloaded in step 1 to the directory where the new Maven will be installed by typing this command:
  cp ~/Desktop/apache-maven-3.0.2-bin.tar.gz /usr/share/java/
Change to the installation directory by entering this command:
  cd /usr/share/java/
Unpack the archive, which will create a new directory called apache-maven-3.0.2:
  tar xzf apache-maven-3.0.2-bin.tar.gz
Remove the archive file - it is no longer needed:
  rm apache-maven-3.0.2-bin.tar.gz
Remove quarantine status from trusted Maven installation files:
  xattr -dr com.apple.quarantine apache-maven-3.0.2/
Reduce the permissions on config and JAR files with these commands:
  chmod 755 /usr/share/java/apache-maven-3.0.2/conf
  chmod 644 /usr/share/java/apache-maven-3.0.2/conf/settings.xml
  chmod 644 /usr/share/java/apache-maven-3.0.2/boot/*.jar
  chmod 644 /usr/share/java/apache-maven-3.0.2/lib/*.jar
At this point, the new Maven is installed. But the command mvn is still linked to the old installation. The next step will fix this.


3. Link /usr/share/maven to /usr/share/java/apache-maven-3.0.2
Change directories:
  cd /usr/share
Remove the link to the old version of Maven:
  unlink maven
Replace the old link with a new soft link to the new Maven 3.0.2 installation:
  ln -s java/apache-maven-3.0.2 maven
Exit the root session:
  exit

Verify Installation
At this point, invoking Maven with the command mvn -v from the Terminal should call the newly installed version:
  bash-3.2$ mvn -v
  Apache Maven 3.0.2 (r1056850; 2011-01-08 16:58:10-0800)
  Java version: 1.6.0_22, vendor: Apple Inc.
  Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  Default locale: en_US, platform encoding: MacRoman
  OS name: "mac os x", version: "10.6.6", arch: "i386", family: "mac"
After successful installation, the directory structure should be:
  /usr/share/maven -> java/apache-maven-3.0.2
  /usr/share/java/apache-maven-3.0.2
  /usr/share/java/apache-maven-3.0.2/bin
  /usr/share/java/apache-maven-3.0.2/bin/m2.conf
  /usr/share/java/apache-maven-3.0.2/bin/mvn
  /usr/share/java/apache-maven-3.0.2/bin/mvn.bat
  /usr/share/java/apache-maven-3.0.2/bin/mvnDebug
  /usr/share/java/apache-maven-3.0.2/bin/mvnDebug.bat
  /usr/share/java/apache-maven-3.0.2/bin/mvnyjp
  /usr/share/java/apache-maven-3.0.2/boot
  /usr/share/java/apache-maven-3.0.2/boot/plexus-classworlds-2.4.jar
  /usr/share/java/apache-maven-3.0.2/conf
  /usr/share/java/apache-maven-3.0.2/conf/settings.xml
  /usr/share/java/apache-maven-3.0.2/lib
  /usr/share/java/apache-maven-3.0.2/lib/aether-api-1.9.jar
  /usr/share/java/apache-maven-3.0.2/lib/aether-connector-wagon-1.9.jar
  /usr/share/java/apache-maven-3.0.2/lib/aether-impl-1.9.jar
  /usr/share/java/apache-maven-3.0.2/lib/aether-spi-1.9.jar
  /usr/share/java/apache-maven-3.0.2/lib/aether-util-1.9.jar
  /usr/share/java/apache-maven-3.0.2/lib/commons-cli-1.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/maven-aether-provider-3.0.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/maven-artifact-3.0.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/maven-compat-3.0.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/maven-core-3.0.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/maven-embedder-3.0.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/maven-model-3.0.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/maven-model-builder-3.0.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/maven-plugin-api-3.0.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/maven-repository-metadata-3.0.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/maven-settings-3.0.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/maven-settings-builder-3.0.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/nekohtml-1.9.6.2.jar
  /usr/share/java/apache-maven-3.0.2/lib/plexus-cipher-1.4.jar
  /usr/share/java/apache-maven-3.0.2/lib/plexus-component-annotations-1.5.5.jar
  /usr/share/java/apache-maven-3.0.2/lib/plexus-interpolation-1.14.jar
  /usr/share/java/apache-maven-3.0.2/lib/plexus-sec-dispatcher-1.3.jar
  /usr/share/java/apache-maven-3.0.2/lib/plexus-utils-2.0.4.jar
  /usr/share/java/apache-maven-3.0.2/lib/sisu-guice-2.9.1-noaop.jar
  /usr/share/java/apache-maven-3.0.2/lib/sisu-inject-bean-1.4.3.1.jar
  /usr/share/java/apache-maven-3.0.2/lib/sisu-inject-plexus-1.4.3.1.jar
  /usr/share/java/apache-maven-3.0.2/lib/wagon-file-1.0-beta-7.jar
  /usr/share/java/apache-maven-3.0.2/lib/wagon-http-lightweight-1.0-beta-7.jar
  /usr/share/java/apache-maven-3.0.2/lib/wagon-http-shared-1.0-beta-7.jar
  /usr/share/java/apache-maven-3.0.2/lib/wagon-provider-api-1.0-beta-7.jar
  /usr/share/java/apache-maven-3.0.2/lib/xercesMinimal-1.9.6.2.jar
  /usr/share/java/apache-maven-3.0.2/LICENSE.txt
  /usr/share/java/apache-maven-3.0.2/NOTICE.txt
  /usr/share/java/apache-maven-3.0.2/README.txt
The Windows .bat files in the bin directory are not needed, but they don't hurt anything. The original archive downloaded to the Desktop can be safely removed now that Maven was upgraded successfully.


Alternative Installation Methods
If you are already using MacPorts, you can upgrade Maven using this simple command:
  sudo port install maven3
If you wish to install MacPorts, check the MacPorts installation page for more information. There are .dmg disk images available for Snow Leopard that make installation very easy.


1 comment: