[英]Java: com.sun.tools.javac.Main not found when trying to compile Hadoop program
When I try to compile my program in Hadoop with this command 当我尝试使用此命令在Hadoop中编译我的程序时
bin/hadoop com.sun.tools.javac.Main WordCounter.java
from Hadoop folder, it says 它说,来自Hadoop文件夹
Error: Could not find or load main class com.sun.tools.javac.Main
I looked in similar threads where people suggested to check if JAVA_HOME
is properly stated. 我查看了类似的线程,人们建议检查JAVA_HOME
是否正确陈述。 So in etc/hadoop/hadoop-env.sh
I added this line 所以在etc/hadoop/hadoop-env.sh
我添加了这一行
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
then checked if tools.pack
is properly unpacked in /usr/lib/jvm/java-7-openjdk-amd64/lib
and it was. 然后检查tools.pack
是否在/usr/lib/jvm/java-7-openjdk-amd64/lib
正确解压缩。 Then I tried javac -version
which gave 然后我尝试了javac -version
javac 1.7.0_65
I tried to reinstall Java but it didn't solve the problem. 我试图重新安装Java,但它没有解决问题。
尝试设置HADOOP_CLASSPATH环境变量
export HADOOP_CLASSPATH=$JAVA_HOME/lib/tools.jar
The error means you don't use a JDK to start Hadoop. 该错误意味着您不使用JDK来启动Hadoop。 The main difference between the JRE (pure runtime) and the JDK is the Java compiler javac
. JRE(纯运行时)和JDK之间的主要区别是Java编译器javac
。 To see if you have a Java compiler, you need to check two places: There should be a javac
in the $JAVA_HOME/bin
folder plus there must be a file $JAVA_HOME/lib/tools.jar
. 要查看是否有Java编译器,需要检查两个位置: $JAVA_HOME/bin
文件夹中应该有一个javac
,并且必须有一个文件$JAVA_HOME/lib/tools.jar
。
In your case, the first one (the binary to start the compiler) can be missing but you absolutely need the tools.jar
. 在您的情况下,第一个(启动编译器的二进制文件)可能会丢失,但您绝对需要tools.jar
。
You say that you have a tools.pack
but I haven't heard about this one before. 你说你有一个tools.pack
但我以前没有听说过这个。 Use your package manager to search for openjdk
and then look for a package in the result list which says jdk
. 使用包管理器搜索openjdk
,然后在结果列表中查找包含jdk
。 On my system, that would be openjdk-7-jdk
. 在我的系统上,那将是openjdk-7-jdk
。 Install this package and the error should go away. 安装此软件包,错误应该消失。
I had to downgrade Hadoop to 2.9.2 and it's working. 我不得不将Hadoop降级到2.9.2并且它正在运行。
I also had these in my environment: 我在我的环境中也有这些:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export PATH=${JAVA_HOME}/bin:${PATH}
export HADOOP_CLASSPATH=${JAVA_HOME}/lib/tools.jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.