Ticker

6/recent/ticker-posts

Ad Code

Responsive Advertisement

How to Install Maven on Mac OS X Manually? Fix UnsupportedClassVersion Error: org/apache/maven /cli/MavenCli

How to Install Maven on Mac OS X manually

Maven build is the first think we do after working on daily codebase. I usually perform Maven Build hundreds of time in a day. As you may have noticed, on Crunchify almost all of our projects are based on Maven.

Maven is one of the best thing happened to Java Developer community.

With simple maven clean install, maven clean deploy and more command, your word project just builds and deployed with all dependencies. Maven downloads all of the dependencies download to the path specified in settings.xml file.

Do you have a new Macbook Pro and is your Mac running on latest Mac OS X version? If yes, it doesn’t come by default with Maven installed.

Check this out 🙁

bash-3.2$ mvn clean install
bash: mvn: command not found

bash-3.2$ mvn eclipse:eclipse
bash: mvn: command not found

If you have any of below questions then you are at right place:
  • Maven – Installing Apache Maven
  • How to install Maven on Mac OSX
  • How to ensure maven is installed in mac
  • How to install Maven on Mac OS X without Homebrew?

In this tutorial we will go over steps on how to install Maven on Mac OS X. Let’s get started:

Step-1

Download lates Maven version apache-maven-3.6.0-bin.tar.gz from official site.

We are using linux wget command to download it.

Here is a mirror download location: https://ift.tt/7TK5N9H

bash-3.2$ mkdir ~/crunchify

bash-3.2$ cd ~/crunchify/

bash-3.2$ pwd
/Users/ashah/crunchify

bash 3.2$ wget http://mirrors.koehn.com/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.zip
--2019-01-17 21:20:50--  http://mirrors.koehn.com/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.zip
Resolving mirrors.koehn.com (mirrors.koehn.com)... 209.240.109.238
Connecting to mirrors.koehn.com (mirrors.koehn.com)|209.240.109.238|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9102386 (8.7M) [application/zip]
Saving to: ‘apache-maven-3.6.0-bin.zip’

apache-maven-3.6.0-bin.zip             100%[==========================================================================>]   8.68M  3.25MB/s    in 2.7s    

2019-01-17 21:20:53 (3.25 MB/s) - ‘apache-maven-3.6.0-bin.zip’ saved [9102386/9102386]

Above command will download .zip file to /Users/ashah/crunchify folder.

Step-2

Go to ~/crunchify/ folder or /Users/ashah/crunchify folder.

Extract apache-maven-3.6.0-bin.zip file using unzip command.

bash-3.2$ cd ~/crunchify

bash-3.2$ unzip apache-maven-3.6.0-bin.zip 
Archive:  apache-maven-3.6.0-bin.zip
   creating: apache-maven-3.6.0/
   creating: apache-maven-3.6.0/lib/
   creating: apache-maven-3.6.0/lib/jansi-native/
   creating: apache-maven-3.6.0/lib/jansi-native/freebsd32/
   creating: apache-maven-3.6.0/lib/jansi-native/freebsd64/
   creating: apache-maven-3.6.0/lib/jansi-native/linux32/
   creating: apache-maven-3.6.0/lib/jansi-native/linux64/
   creating: apache-maven-3.6.0/lib/jansi-native/osx/
   creating: apache-maven-3.6.0/lib/jansi-native/windows32/
   creating: apache-maven-3.6.0/lib/jansi-native/windows64/
   creating: apache-maven-3.6.0/bin/
   creating: apache-maven-3.6.0/conf/

New Maven folder created - Crunchify Tips

Step-3

Next thing is to setup classpath.

Setup maven classpath to your environment variable by updating .bash_profile file.

bash-3.2$ sudo vi ~/.bash_profile

Add below two lines and save the file.
export M2_HOME=/Users/ashah/crunchify/apache-maven-3.6.0
export PATH=$PATH:$M2_HOME/bin

Step-4

How to reload .bash_profile from the command line?

bash-3.2$ source ~/.bash_profile

Or execute below command.
bash-3.2$ . ~/.bash_profile

Step-5

Now try again mvn -version and you are all set.

bash-3.2$ mvn -version
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T13:41:47-05:00)
Maven home: /Users/ashah/crunchify/apache-maven-3.6.0
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.2", arch: "x86_64", family: "mac"

bash-3.2$

Maven start working again on Mac OSX terminal window - Crunchify Tips

Facing this error?

Are you getting below error while running command mvn -version?

bash-3.2$ mvn -version
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)

The problem is because you haven’t set JAVA_HOME in Mac properly. In order to fix that add below line to .bash_profile before export M2_HOME line.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home

In my case my JDK installation is jdk1.8.0_91.jdk, make sure you type yours.

.bash_profile file with JDK Path:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home
export M2_HOME=/Users/ashah/crunchify/apache-maven-3.6.0
export PATH=$PATH:$M2_HOME/bin

And you are all set.

Just try running maven and you won’t see any issue. I hope this tutorial will help you setup Maven path on Mac OSX quickly and easily.

The post How to Install Maven on Mac OS X Manually? Fix UnsupportedClassVersion Error: org/apache/maven /cli/MavenCli appeared first on Crunchify.

Enregistrer un commentaire

0 Commentaires