Ondra K.
Ondra K.

Reputation: 3097

Maven error: Could not find or load main class .usr.share.maven.boot.plexus-classworlds-2.x.jar

I have recently upgraded my Ubuntu from 14.04 to 16.04 and started getting the following error when running any mvn commands (version 3.3.9): Error: Could not find or load main class .usr.share.maven.boot.plexus-classworlds-2.x.jar. My environment variables are declared as follows:

$JAVA_HOME: /usr/lib/jvm/java-8-oracle $PATH: /usr/local/texlive/2015/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin $M2_HOME: /usr/share/maven $M2: /usr/share/maven/bin

When trying to find a solution, I've tried removing the M2 and M2_HOME variables as suggested on various threads, which resulted in getting a different error: Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher. I have also tried running apt-get remove --purge maven and installing it again as well as downloading the .tar.gz archive, but in both cases, nothing has changed.

When looking into the /usr/share/maven/boot folder, there is a chain of symlinks pointing from plexus-classworlds-2.x.jar -> /usr/share/java/plexus-classworlds2-2.5.2.jar. Am I missing some dependencies? Or are there any old configuration files that did not get removed by --purge?

EDIT: When I execute mvn as root, I get the Launcher error instead of plexus-classworlds-2.x. Also, I have completely removed and reinstalled all plexus libraries, yet with no change.

Upvotes: 1

Views: 2336

Answers (1)

Kos Prov
Kos Prov

Reputation: 4293

Check if /usr/share/maven/boot has multiple jars with pattern /usr/share/maven/boot/plexus-classworlds-*.jar.

Mine was something like:

drwxr-xr-x 2 root root  4096 Dec  23 14:21 ./
drwxr-xr-x 6 root root  4096 Nov  14  2015 ../
-rw-r--r-- 1 root root 52684 Dec  12  2015 plexus-classworlds-2.5.2.jar
lrwxrwxrwx 1 root root    34 Dec  10  2015 plexus-classworlds-2.x.jar -> ../../java/plexus-classworlds2.jar

This messes up /usr/share/maven/bin/mvn bash script and executes a wrong java command.

I had to remove the jar and leave only the symbolic link.

Upvotes: 5

Related Questions