如何运行Hadoop程序? [英] How to run a Hadoop program?

查看:197
本文介绍了如何运行Hadoop程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在笔记本电脑上安装了Hadoop,并成功运行了安装指南中给出的示例程序。但是,我无法运行程序。

  rohit @ renaissance1:〜/ hadoop / ch2 $ hadoop MaxTemperature输入/ ncdc / sample.txt输出
例外线程mainjava.lang.NoClassDefFoundError:MaxTemperature
导致:java.lang.ClassNotFoundException:MaxTemperature
在java.net.URLClassLoader $ 1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native方法)$ b $ java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:301)$ b $ at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
无法找到主类: MaxTemperature。程序将会退出。

这本书说我们应该通过编写一个Hadoop类路径

  rohit @ renaissance1:〜/ hadoop / ch2 $ export HADOOP_CLASSPATH = build / classes 

主类在我正在执行的MaxTemperature.java文件中定义。我们如何设置Hadoop类路径?我们必须为所有程序执行还是只执行一次?我应该在哪里放置输入文件夹。我的代码位于/ home / rohit / hadoop / ch2,而我的Hadoop安装位于/ home / hadoop。

解决方案

您应该将应用程序打包到JAR文件中,这比调用classpath文件夹更容易,更容易出错。 / p>

就你而言,你还必须编译.java文件。你说它是MaxTemparature.java,但在运行之前还必须有一个MaxTemperature.class。


I have set up Hadoop on my laptop and ran the example program given in the installation guide successfully. But, I am not able to run a program.

rohit@renaissance1:~/hadoop/ch2$ hadoop MaxTemperature input/ncdc/sample.txt output
Exception in thread "main" java.lang.NoClassDefFoundError: MaxTemperature
Caused by: java.lang.ClassNotFoundException: MaxTemperature
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: MaxTemperature.  Program will exit.

The book said that we should set a Hadoop Classpath by writing

rohit@renaissance1:~/hadoop/ch2$ export HADOOP_CLASSPATH=build/classes

The main class is defined in MaxTemperature.java file that I am executing. How do we set the Hadoop Classpath? Do we have to do it for all program execution or only once? Where should I put the input folder. My code is at /home/rohit/hadoop/ch2 and my Hadoop installation is at /home/hadoop.

解决方案

You should package your application into a JAR file, that's much easier and less error-prone than fiddling with classpath folders.

In your case, you must also compile the .java file. You said it's MaxTemparature.java, but there must also be a MaxTemperature.class before you can run it.

这篇关于如何运行Hadoop程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆