Error: Could not find or load main class org.codeh

2020-03-21 10:12发布

问题:

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?

回答1:

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.



回答2:

I would recommend a fresh installation of maven. First , remove all installations of all versions of maven from your system

$ sudo apt-get remove maven

Next, instead of downloading from the package manager, download it from the offical Apache website. I would recommend getting the latest version of maven (3.1.X), and extract it in a directory where you have read/write privileges.

$ tar -xvf apache-maven-3.1.1.tar.gz

Lastly update all symlinks and home variables set for maven. You have a choice of defining the environment variables.

  1. /etc/environment -> Some people don't recomment setting global variables here due to obvious reasons.
  2. /etc/bashrc -> I personally use this to export any environment variables I want.


回答3:

I got this error too. Turns out I had forgotten to restart my shell.

Once I closed Terminal and opened it again, the error did not come back and Maven worked.



回答4:

I faced the same issue in Windows 8 but in my case maven directory e.g apache-maven-3.3.3 was hidden.

Post removing hidden option from the directory apache-maven-3.3.3 worked for me .



回答5:

Solved for me on Ubuntu 18.04:

$ sudo apt-get remove maven

$ sudo apt-get purge maven

$ sudo apt-get install maven