Error: Could not find or load main class org.codehaus.classworlds.Launcher while building Maven 3.0.4

apache, java, linux, maven, ubuntu

Solution

The below answer (setting M3_HOME instead of M2_HOME) solved my issue http://www.johnlabarge.com/post/33156663109/dreaded-maven-error-could-not-find-or-load-main-class

I had this little issue on my Mac after installing maven3 and jdk1.7. Here is what fixed my issue:

1) Remove the M2_HOME variable from the path.

2) Add M3_HOME variable with the path to your maven 3 installation.

Here is the interesting part: I use symbolic links for versioning. The values of both M2_HOME and M3_HOME were identical. Both were /Developer/maven. Hence it appears that the name M2_HOME in place of M3_HOME is what actually causes the issue. I leave it as an exercise (that I may return to) to find the issue in the source.

Problem

I have used `apt-get install maven2` to install maven2.2.1. In order to compile hadoop 2.1.0 source program, I need to upgrade the maven version, but it is not able to use `apt-get` again, because maven2.1.0 is the latest in the lib. I downloaded `apache-maven-3.0.5-bin.tar.gz` from the official website, ran `tar apache-maven-3.0.5-bin.tar.gz` at the path `/usr/local`, and put `apache-maven` links to apache-maven-3.0.5: ``` lrwxrwxrwx 1 root root 18 Dec 8 11:26 apache-maven -> apache-maven-3.0.5 drwxr-xr-x 6 root root 1024 Dec 8 11:12 apache-maven-3.0.5 export the order in the terminal like this: export M2_HOME=/usr/local/apache-maven export PATH=$PATH:$M2_HOME/bin ``` input order "export" to identify : ``` ............................................. declare -x M2_HOME="/usr/local/apache-maven" declare -x MANDATORY_PATH="/usr/share/gconf/ubuntu.mandatory.path" declare -x OLDPWD="/usr" declare -x PATH="/usr/lib/lightdm/lightdm:/usr/local/java/latest/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/apache-maven/bin" ``` All signs showed maven 3.0.5 has succeeded in configuration, but when I input `mvn -version` in the terminal, it show errors like this: ``` Error: Could not find or load main class org.codehaus.classworlds.Launcher ``` If I change a new terminal and input `mvn -version`, it shows: ``` administrator@ubuntu:~$ mvn -version Apache Maven 2.2.1 (rdebian-8) Java version: 1.7.0_45 Java home: /usr/local/java/jdk1.7.0_45/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux" version: "3.5.0-17-generic" arch: "amd64" Family: "unix" ``` It happens every time although I had uninstalled maven 2.2.1 by running: `sudo apt-get remove --purge maven` I do not know why? I have not uninstalled it completely?

Original source