Linux 错误:在构建 Maven 3.0.4 时无法找到或加载主类 org.codehaus.classworlds.Launcher
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20449836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Could not find or load main class org.codehaus.classworlds.Launcher while building Maven 3.0.4
提问by user3079078
I have used apt-get install maven2
to install maven2.2.1. In order to compile hadoop 2.1.0source program, I need to upgrade the mavenversion, but it is not able to use apt-get
again, because maven2.1.0is the latest in the lib.
我曾经apt-get install maven2
安装过maven2.2.1。为了编译hadoop 2.1.0源程序,我需要升级maven版本,但是不能apt-get
再次使用,因为maven2.1.0是最新的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:
我是apache-maven-3.0.5-bin.tar.gz
从官网下载的,跑到tar apache-maven-3.0.5-bin.tar.gz
path /usr/local
,把apache-maven
链接放到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.5has succeeded in configuration, but when I input
所有迹象表明maven 3.0.5已经配置成功,但是当我输入
mvn -version
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:
如果我更改一个新终端并输入mvn -version
,它会显示:
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.1by running:
尽管我通过运行卸载了maven 2.2.1,但每次都会发生:
sudo apt-get remove --purge maven
sudo apt-get remove --purge maven
I do not know why? I have not uninstalled it completely?
我不知道为什么?我还没有完全卸载吗?
回答by Saif Asif
I would recommend a fresh installation of maven. First , remove all installations of all versions of maven from your system
我会推荐一个全新的 maven 安装。首先,从您的系统中删除所有版本的 maven 的所有安装。
$ sudo apt-get remove maven
$ 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.
接下来,不是从包管理器下载,而是从官方 Apache 网站下载。我建议获取最新版本的 maven (3.1.X),并将其解压缩到您具有读/写权限的目录中。
$ tar -xvf apache-maven-3.1.1.tar.gz
$ 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.
最后更新为 maven 设置的所有符号链接和主变量。您可以选择定义环境变量。
/etc/environment
-> Some people don't recomment setting global variables here due to obvious reasons./etc/bashrc
-> I personally use this to export any environment variables I want.
/etc/environment
-> 由于显而易见的原因,有些人不建议在此处设置全局变量。/etc/bashrc
-> 我个人使用它来导出我想要的任何环境变量。
回答by SK Nair
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
以下答案(设置 M3_HOME 而不是 M2_HOME)解决了我的问题 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.
安装 maven3 和 jdk1.7 后,我在 Mac 上遇到了这个小问题。这是解决我的问题的方法:
1) 从路径中删除 M2_HOME 变量。
2) 将 M3_HOME 变量添加到您的 maven 3 安装路径。
这是有趣的部分:我使用符号链接进行版本控制。M2_HOME 和 M3_HOME 的值相同。两者都是/Developer/maven。因此,名称 M2_HOME 代替 M3_HOME 似乎是导致问题的真正原因。我将其作为练习(我可能会返回)以在源中找到问题。
回答by PanicBus
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.
一旦我关闭终端并再次打开它,错误就没有回来并且 Maven 工作。
回答by user3123256
I faced the same issue in Windows 8 but in my case maven directory e.g apache-maven-3.3.3 was hidden.
我在 Windows 8 中遇到了同样的问题,但在我的情况下,maven 目录,例如 apache-maven-3.3.3 被隐藏了。
Post removing hidden option from the directory apache-maven-3.3.3 worked for me .
从目录 apache-maven-3.3.3 中删除隐藏选项后对我有用。
回答by Clayton Marinho
Solved for me on Ubuntu 18.04:
在 Ubuntu 18.04 上为我解决:
$ sudo apt-get remove maven
$ sudo apt-get purge maven
$ sudo apt-get install maven