hadoop-0.20.2安装找不到JAVA_HOME解决办法

在安装hadoop-0.20.2时出现了找不到JAVA_HOME,配置方法跟官方的版本一致,具体请参考前边的文章或者网上的文档。[color=darkred]最好每台机子上配置的JDK都一样,要不然会出现很奇怪的问题[/color]。配置好以后,运行start-all.sh时,确出现如下的报错:
======================================================================+
| [color=red]Error: JAVA_HOME is not set and Java could not be found [/color] |
+----------------------------------------------------------------------+
| Please download the latest Sun JDK from the Sun Java web site |
| > http://java.sun.com/javase/downloads/ < |
| |
| Hadoop requires Java 1.6 or later. |
| NOTE: This script will find Sun Java whether you install using the |
| binary or the RPM based installer. |
+======================================================================+
明明在hadoop-env.sh设置好了,为了保险,又在/etc/profile设置了一遍。以hadoop用户登陆系统,在任意路径执行 echo $JAVA_HOME ,显示"/usr/local/jdk",是我服务器jdk正确的路径啊!再查一下文档,云:需要jdk1.6以上的版本,我使用的是 jdk1.6.0_16,应该符合要求的。

那问题又会在哪里呢?grep一把,看那些文件包含字符串JAVA_HOME.先搜hadoop/conf,只有hadoop-env.sh包含这个字串。再换一个目录hadoop/bin,查看一下,其输出如下:
# grep JAVA_HOME bin/*bin/hadoop:export JAVA_HOME=/usr/local/jdkbin/hadoop:# JAVA_HOME The java implementation to use. Overrides JAVA_HOME.
bin/hadoop:if [ "$JAVA_HOME" != "" ]; then
bin/hadoop: #echo "run java in $JAVA_HOME"
bin/hadoop: JAVA_HOME=$JAVA_HOME
bin/hadoop:if [ "$JAVA_HOME" = "" ]; then
bin/hadoop: echo "Error: JAVA_HOME is not set."
bin/hadoop:JAVA=$JAVA_HOME/bin/java
bin/hadoop:CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar
bin/hadoop-config.sh:if [ -z "$JAVA_HOME" ]; then
bin/hadoop-config.sh: export JAVA_HOME=$candidate
bin/hadoop-config.sh: if [ -z "$JAVA_HOME" ]; then
bin/hadoop-config.sh:| Error: JAVA_HOME is not set and Java could not be found |
bin/rcc:# JAVA_HOME The java implementation to use. Overrides JAVA_HOME.
bin/rcc:if [ "$JAVA_HOME" != "" ]; then
bin/rcc: #echo "run java in $JAVA_HOME"
bin/rcc: JAVA_HOME=$JAVA_HOME
bin/rcc:if [ "$JAVA_HOME" = "" ]; then
bin/rcc: echo "Error: JAVA_HOME is not set."
bin/rcc:JAVA=$JAVA_HOME/bin/java
bin/rcc:CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar

嘿!好几个文件都与JAVA_HOME相关呢。接着挨个查看文件,感觉hadoop-config.sh这个文件嫌疑最大,其内容刚好有一段与运行hadoop报错内容相一致,我把程序片段贴在下面:
# attempt to find java
if [ -z "$JAVA_HOME" ]; then
for candidate in \
/usr/lib/jvm/java-6-sun \
/usr/lib/j2sdk1.6-sun \
/usr/local/jdk \
/usr/java/jdk1.6* \
/usr/java/jre1.6* \
/Library/Java/Home ; do
if [ -e $candidate/bin/java ]; then
export JAVA_HOME=$candidate
break
fi
done
# if we didn't set it
if [ -z "$JAVA_HOME" ]; then
cat 1>&2 <<EOF
+======================================================================+
| Error: JAVA_HOME is not set and Java could not be found |
+----------------------------------------------------------------------+
| Please download the latest Sun JDK from the Sun Java web site |
| > http://java.sun.com/javase/downloads/ < |
| |
| Hadoop requires Java 1.6 or later. |
| NOTE: This script will find Sun Java whether you install using the |
| binary or the RPM based installer. |
+=====================================================================
我在这段中间加如行 [color=red]" /usr/local/jdk \"[/color],然后在运行,一切就正常了!
希望对大家有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值