Thursday, December 15, 2011

maven2 - maven3 and java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher

I typically use  maven2 as my builder manager  and I had to install maven3 to use in the same machine for build a new source code. I used following simple hack for this.
1. Download and extract maven3 distribution to any place as you prefer.
(MAVEN3_HOME = path of root of the extracted  distribution)
2. Rename one of the mvn file in MAVEN3_HOME/bin
You can use rename MAVEN3_HOME/bin/mvn mvn3 or mv  MAVEN3_HOME/bin/mvn mvn3
3. Add MAVEN3_HOME/bin to the environment variable in /etc/environment or /etc/bash.bashrc
4. Restart the shell/terminal
Now you can use both maven2 and maven3 using mvn and mvn3 commands.

Also you cannot use maven2 and maven3 shared m2 repository. You can do that by allocating different spaces for maven2 m2 repo and maven3 m2 repo. For more details click here.

After doing this when I execute mvn3 clean install I got the following exception.
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher

Solution:
First guess: The cause of this should be installing maven2 and maven3 in the same machine. But theoretically this cannot happened. Because we invoke maven2 and maven3 using different commands which locates in different places.
Second guess: There may some environmental variable which belongs to maven2 accessed by maven3. Fortunately the second guess was right. I exported M2_HOME in /etc/bash.bashrc file which direct to the maven2 root. After commenting out that piece of code mvn3 clean install worked fine for me.
WARNING: Programs which uses M2_HOME variable may not work properly after this modification.


NOTE: This is only one cause which throws this exception. There may more. Here is another example which throws the same exception but when executing maven2.

6 comments: