博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hadoop运行java类
阅读量:5778 次
发布时间:2019-06-18

本文共 5948 字,大约阅读时间需要 19 分钟。

hot3.png

使用hadoop运行自己写的java类报错:

/home/hadoop/bin/hadoop MaxTemperature /home/hadoop/input/sample.txt outputException in thread "main" java.lang.NoClassDefFoundError: MaxTemperatureCaused 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:306)	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)Could not find the main class: MaxTemperature.  Program will exit.
查了很多资料,总结运行java类的步骤。

步骤1:设置java环境变量,编辑 conf/hadoop-env.sh文件,至少需要将JAVA_HOME设置为Java安装根路径。

步骤2:行java程序时要先编译成class文件,才能用hadoop命令,但是编译的时候会有如下错误:

axTemperature.java:5: 软件包 org.apache.hadoop.fs 不存在import org.apache.hadoop.fs.Path;                           ^MaxTemperature.java:6: 软件包 org.apache.hadoop.io 不存在import org.apache.hadoop.io.IntWritable;                           ^MaxTemperature.java:7: 软件包 org.apache.hadoop.io 不存在import org.apache.hadoop.io.Text;                           ^MaxTemperature.java:8: 软件包 org.apache.hadoop.mapred 不存在import org.apache.hadoop.mapred.FileInputFormat;                               ^MaxTemperature.java:9: 软件包 org.apache.hadoop.mapred 不存在import org.apache.hadoop.mapred.FileOutputFormat;....
上面的信息很明确,找不到hadoop相关的java类,请在CLASSPATH设置一下

export CLASSPATH=.:/home/hadoop/hadoop-0.20.2-core.jar:$CLASSPATH
步骤3:运行自己写的java类。

有的时候报错:

root@tianbaoxing-virtual-machine:/home/hadoop/java# /home/hadoop/bin/hadoop MaxTemperature /home/hadoop/input/sample.txt outputException in thread "main" java.lang.NoClassDefFoundError: MaxTemperatureCaused 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:306)	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)Could not find the main class: MaxTemperature.  Program will exit.
上面的信息报错找不到运行的类,
是因为没有设置classpath,在hadoop环境下怎么设置classpath呢?

export HADOOP_CLASSPATH=/home/hadoop/java
我把要运行的java类全部放在了/home/hadoop/java 这个文件夹下面了。

最后正确的运行结果:

/home/hadoop/bin/hadoop MaxTemperature /home/hadoop/input/sample.txt output13/04/10 11:00:31 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=13/04/10 11:00:31 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.13/04/10 11:00:32 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).13/04/10 11:00:32 INFO mapred.FileInputFormat: Total input paths to process : 113/04/10 11:00:33 INFO mapred.JobClient: Running job: job_local_000113/04/10 11:00:33 INFO mapred.FileInputFormat: Total input paths to process : 113/04/10 11:00:33 INFO mapred.MapTask: numReduceTasks: 113/04/10 11:00:33 INFO mapred.MapTask: io.sort.mb = 10013/04/10 11:02:48 INFO mapred.MapTask: data buffer = 79691776/9961472013/04/10 11:02:48 INFO mapred.MapTask: record buffer = 262144/32768013/04/10 11:02:48 INFO mapred.LocalJobRunner: file:/home/hadoop/input/sample.txt:0+233613/04/10 11:02:48 INFO mapred.JobClient:  map 0% reduce 0%13/04/10 11:02:48 INFO mapred.MapTask: Starting flush of map output13/04/10 11:02:52 INFO mapred.MapTask: Finished spill 013/04/10 11:02:52 INFO mapred.TaskRunner: Task:attempt_local_0001_m_000000_0 is done. And is in the process of commiting13/04/10 11:02:52 INFO mapred.LocalJobRunner: file:/home/hadoop/input/sample.txt:0+233613/04/10 11:02:52 INFO mapred.TaskRunner: Task 'attempt_local_0001_m_000000_0' done.13/04/10 11:02:52 INFO mapred.LocalJobRunner: 13/04/10 11:02:52 INFO mapred.Merger: Merging 1 sorted segments13/04/10 11:02:52 INFO mapred.JobClient:  map 100% reduce 0%13/04/10 11:02:52 INFO mapred.Merger: Down to the last merge-pass, with 1 segments left of total size: 189 bytes13/04/10 11:02:52 INFO mapred.LocalJobRunner: 13/04/10 11:02:53 INFO mapred.TaskRunner: Task:attempt_local_0001_r_000000_0 is done. And is in the process of commiting13/04/10 11:02:53 INFO mapred.LocalJobRunner: 13/04/10 11:02:53 INFO mapred.TaskRunner: Task attempt_local_0001_r_000000_0 is allowed to commit now13/04/10 11:02:53 INFO mapred.FileOutputCommitter: Saved output of task 'attempt_local_0001_r_000000_0' to file:/home/hadoop/java/output13/04/10 11:02:53 INFO mapred.LocalJobRunner: reduce > reduce13/04/10 11:02:53 INFO mapred.TaskRunner: Task 'attempt_local_0001_r_000000_0' done.13/04/10 11:02:53 INFO mapred.JobClient:  map 100% reduce 100%13/04/10 11:02:53 INFO mapred.JobClient: Job complete: job_local_000113/04/10 11:02:53 INFO mapred.JobClient: Counters: 1313/04/10 11:02:53 INFO mapred.JobClient:   FileSystemCounters13/04/10 11:02:53 INFO mapred.JobClient:     FILE_BYTES_READ=3048513/04/10 11:02:53 INFO mapred.JobClient:     FILE_BYTES_WRITTEN=5240013/04/10 11:02:53 INFO mapred.JobClient:   Map-Reduce Framework13/04/10 11:02:53 INFO mapred.JobClient:     Reduce input groups=213/04/10 11:02:53 INFO mapred.JobClient:     Combine output records=013/04/10 11:02:53 INFO mapred.JobClient:     Map input records=1713/04/10 11:02:53 INFO mapred.JobClient:     Reduce shuffle bytes=013/04/10 11:02:53 INFO mapred.JobClient:     Reduce output records=213/04/10 11:02:53 INFO mapred.JobClient:     Spilled Records=3413/04/10 11:02:53 INFO mapred.JobClient:     Map output bytes=15313/04/10 11:02:53 INFO mapred.JobClient:     Map input bytes=233613/04/10 11:02:53 INFO mapred.JobClient:     Combine input records=013/04/10 11:02:53 INFO mapred.JobClient:     Map output records=1713/04/10 11:02:53 INFO mapred.JobClient:     Reduce input record=17

转载于:https://my.oschina.net/winHerson/blog/122294

你可能感兴趣的文章
openldap mirrormode 配置
查看>>
C# url元素分解
查看>>
防火墙之地址转换SNAT DNAT
查看>>
基于php实现长连接的方法与注意事项的问题
查看>>
Visual.Basic语法基础之一
查看>>
linux运维实战练习-正则表达式
查看>>
RHEL6基础之四RHEL系统安装
查看>>
无法复制 参数不正确,U盘无法复制文件解决方法
查看>>
Library Cache库缓存
查看>>
Linux系统实用命令总结
查看>>
详解Nginx + Tomcat 反向代理 负载均衡 集群 部署指南
查看>>
与树莓派共享目录 —— Windows自带NFS客户端?
查看>>
WLAN 无线网络 06 - WLAN 设备,接入点,客户端,服务集
查看>>
PMC向数据中心敞开12Gb/s SAS大门
查看>>
轻松理解 ISO8583 报文协议(转)
查看>>
我的友情链接
查看>>
解决Cisco ××× Client Reason 442: Failed to Enable Virtual Adapter
查看>>
小插曲(1)
查看>>
[20190401]关于semtimedop函数调用.txt
查看>>
通过PdfiumViewer.dll实现pdf直接从流显示(效果不好)
查看>>