简体   繁体   English

启动时出现“错误:找不到或无法加载主类” Hadoop

[英]"Error: Could not find or load main class" when starting Hadoop

I'm trying to run Hadoop (2.2.0) on my Windows 7 machine (yes, I know that it would be better to run it on Linux, but it is not an option at this moment).我正在尝试在我的 Windows 7 机器上运行 Hadoop (2.2.0)(是的,我知道在 Linux 上运行它会更好,但目前不是一个选项)。 I followed instructions posted at http://ebiquity.umbc.edu/Tutorials/Hadoop/14%20-%20start%20up%20the%20cluster.html and http://blog.sqltrainer.com/2012/01/installing-and-configuring-apache.html我按照http://ebiquity.umbc.edu/Tutorials/Hadoop/14%20-%20start%20up%20the%20cluster.htmlhttp://blog.sqltrainer.com/2012/01/installing-上发布的说明进行操作和-配置-apache.html

Evetyhing went fine until I tried to start Hadoop. Every operation I try to run finishes with: Error: Could not find or load main class... error. Evetyhing 一切顺利,直到我尝试启动 Hadoop。我尝试运行的每个操作都以: Error: Could not find or load main class...错误。
For eg running例如跑步

./hadoop version

end up with以结束

Error: Could not find or load main class org.apache.hadoop.util.VersionInfo

It definitely looks like a problem with classpath.它看起来绝对像是类路径的问题。 However, I have no idea how to solve it.但是,我不知道如何解决它。 I tried to set different environment variables, like $HADOOP_COMMON_HOME or $HADOOP_HOME but without luck.我尝试设置不同的环境变量,例如 $HADOOP_COMMON_HOME 或 $HADOOP_HOME 但没有成功。

Any ideas?有任何想法吗?

This error generally occurs because Hadoop takes your PC name as the default username, which generally contains blank spaces, which is not allowed.出现这个错误一般是因为Hadoop把你的PC名作为默认用户名,一般包含空格,这是不允许的。

To solve this a simple solution would be: Go to hadoop-2.7.1 -> etc -> hadoop -> hadoop-env.cmd Open this hadoop-env.cmd file with any editor such as Notedpad++ and then at the last line replace %USERNAME% with your name without blankspaces.要解决这个问题,一个简单的解决方案是: Go 到 hadoop-2.7.1 -> etc -> hadoop -> hadoop-env.cmd 使用任何编辑器(如 Notepad++)打开此 hadoop-env.cmd 文件,然后在最后一行替换%USERNAME% 加上你的名字,没有空格。 Example:- set HADOOP_IDENT_STRING=TapasVashi示例:- 设置 HADOOP_IDENT_STRING=TapasVashi

PS Also look over throughout the file, there may be other places with %USERNAME%, replace that also with your username but without blankspace. PS 还要查看整个文件,可能还有其他地方有 %USERNAME%,也用你的用户名替换它,但不要有空格。

When you usually get this error message, either you are using the wrong Java version or the program was compiled with an older Java version.当您通常收到此错误消息时,可能是您使用了错误的 Java 版本,或者程序是用较旧的 Java 版本编译的。

You can check your version by opening the cmd (command prompt) and typing java -version .您可以通过打开 cmd(命令提示符)并输入java -version来检查您的版本。

Adding this line to ~/.bash_profile worked for me:将此行添加到 ~/.bash_profile 对我有用:

export HADOOP_PREFIX=/where_ever_you_install_hadoop/hadoop导出 HADOOP_PREFIX=/where_ever_you_install_hadoop/hadoop

FYI, I have the same answer to this post: Could not find or load main class org.apache.hadoop.util.VersionInfo仅供参考,我对这篇文章有相同的回答: Could not find or load main class org.apache.hadoop.util.VersionInfo

I've also been trying to get Windows 7 up and running with Hadoop.我也一直在尝试使用 Hadoop 启动并运行 Windows 7。 For me, the problem was Hadoop is passing CLASSPATH in Cygwin format对我来说,问题是 Hadoop 以 Cygwin 格式传递 CLASSPATH

CLASSPATH=/cygdrive/c/foo:/cygdrive/c/bar

However, Java expects CLASSPATH in Windows format但是,Java 需要 Windows 格式的 CLASSPATH

CLASSPATH=c:\foo;c:\bar

Looking at hadoop-0.19.1 showed me how they handled this.查看 hadoop-0.19.1 向我展示了他们如何处理这个问题。 You may insert the following statements into bin/hadoop , prior to where it calls Java at the end (and repeat for other java-invoking sh scripts)您可以将以下语句插入到bin/hadoop ,在它最后调用 Java 之前(并重复其他调用 java 的 sh 脚本)

cygwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
esac

if $cygwin; then
  echo Cygwin
  CLASSPATH=`cygpath -p -w "$CLASSPATH"`
  HADOOP_HOME=`cygpath -d "$HADOOP_HOME"`
  HADOOP_LOG_DIR=`cygpath -d "$HADOOP_LOG_DIR"`
  TOOL_PATH=`cygpath -p -w "$TOOL_PATH"`
fi

export CLASSPATH=$CLASSPATH
echo $CLASSPATH
exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"

I had faced this problem myself.我自己也遇到过这个问题。 This is what solved the problem for me.这就是为我解决问题的原因。

Add the following to ~/.bashrc file:将以下内容添加到 ~/.bashrc 文件中:

export HADOOP_CLASSPATH=$(cygpath -pw $(hadoop classpath)):$HADOOP_CLASSPATH

Note: You can install Hadoop2.2+ directly on Windows.注意:您可以直接在 Windows 上安装 Hadoop2.2+。 You don't need Cygwin.你不需要 Cygwin。

My problem was the Resource Manager(yarn) was not able to load Hadoop Libraries(jars).我的问题是资源管理器(纱线)无法加载 Hadoop 库(罐子)。 I solved this by updating the configurations.我通过更新配置解决了这个问题。 Added this to yarn-site.xml :将此添加到 yarn-site.xml :

 <property> <name>yarn.application.classpath</name> <value>C:/hadoop-2.8.0/share/hadoop/mapreduce/*,C:/hadoop-2.8.0/share/hadoop/mapreduce/lib/*,C:/Hadoop-2.8.0/share/hadoop/common/*,C:/Hadoop-2.8.0/share/hadoop/common/lib/*, C:/hadoop-2.8.0/share/hadoop/hdfs/*,C:/hadoop-2.8.0/share/hadoop/hdfs/lib/*,C:/hadoop-2.8.0/share/hadoop/yarn/*,C:/hadoop-2.8.0/share/hadoop/yarn/lib/*</value> </property>

Please note that the paths used here can be relative according to your system.请注意,此处使用的路径可以是相对的,具体取决于您的系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hadoop错误:无法找到或加载主类类路径TestJava - Hadoop Error: Could not find or load main class class path TestJava 错误:找不到或加载正在运行Hadoop的主类 - Error: Could not find or load main class Running Hadoop 由于 Could not find or load main class 错误,Flink 集群未启动 - Flink cluster not starting due to Could not find or load main class error 错误:无法在Hadoop上找到或加载主类org.apache.hadoop.hdfs.tools.GetConf - Error: Could not find or load main class org.apache.hadoop.hdfs.tools.GetConf on Hadoop Hadoop 编译错误:无法找到或加载主类 com.sun.tools.javac.Main - Hadoop Compilation Error: Could not find or load main class com.sun.tools.javac.Main 字数统计 hadoop 程序:错误:无法找到或加载主类 com.sun.tools.javac.Main - Word Count hadoop program: Error: Could not find or load main class com.sun.tools.javac.Main 错误:找不到或加载主类Main - Error: Could not find or load main class Main 错误:在CMD中编译时找不到或加载Main类 - error: Could not find or load Main class when compiling in CMD 错误:找不到或加载主类。 编译代码时会发生这种情况 - Error: Could not find or load main class . this occurs when compiling code 添加 maven 依赖项时无法找到或加载主类错误 - Could not find or load main class error when adding maven dependency
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM