hadoop+hbase:ClassNotFoundException:org.apache.hadoop.hbase.HBaseConfiguration

summerhai 2014-08-30 11:08:38
我手里有一份自动生成的模拟登录数据,里面的格式为id#password#email,大概300W条,我想利用hadoop的集群处理优势将这些数据存入到HBase中,以user+i为row key,然后columnFamily包含id,password,email的信息。
下面是代码:(写的经验不足,请多指点)
public class SaveToHBase {
public static int userNumber = 0;
public static String tableName = "UserData";
public static String columnFamily = "userinfo";
public static Configuration cfg = HBaseConfiguration.create();

public static class Map extends Mapper<LongWritable, Text, Text, Text>{
public void map(LongWritable key,Text value,Context context) throws IOException, InterruptedException{
context.write(new Text("user"+userNumber), value);
userNumber++;
}
}

public static class Reduce extends Reducer<Text, Text, Text, Text>{
public void reduce(Text key,Text value,Context context) throws IOException, InterruptedException{
String[] data = value.toString().trim().split("#");
SaveToHBase.put(tableName, key.toString(), columnFamily, "id", data[0]);
SaveToHBase.put(tableName, key.toString(), columnFamily, "password", data[1]);
SaveToHBase.put(tableName, key.toString(), columnFamily, "email", data[2]);
context.write(key,value);
}
}

public static void put(String tableName,String row,String columnFamily,String column,String data) throws IOException{
HTable table = new HTable(cfg, tableName);
Put put = new Put(Bytes.toBytes(row));
put.add(Bytes.toBytes(columnFamily),Bytes.toBytes(column),Bytes.toBytes(data));
table.put(put);
}

public static void create(String tableName, String columnFamily) throws Exception{
HBaseAdmin admin = new HBaseAdmin(cfg);

HTableDescriptor tableDescriptor = new HTableDescriptor(tableName);
tableDescriptor.addFamily(new HColumnDescriptor(columnFamily));
admin.createTable(tableDescriptor);
}

public static boolean delete(String tableName) throws Exception{
HBaseAdmin admin = new HBaseAdmin(cfg);
if(admin.tableExists(tableName)){
try {
admin.disableTable(tableName);
admin.deleteTable(tableName);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return false;
}
}
return true;
}

public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
// SaveToHBase.delete(tableName);
SaveToHBase.create(tableName, columnFamily);
Job job = new Job(conf, "Save ");
job.setJarByClass(SaveToHBase.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}

}

从这个工程中导出jar包,然后指定输入输出目录,然后就遇到ClassNotFoundException:org.apache.hadoop.hbase.HBaseConfiguration这个错误了,我已经做了一些调整:
1,导入了hbase-site.xml文件
2,导入了hbase-0.94.13.jar
根据http://blog.csdn.net/zwx19921215/article/details/21531015这里的提示,放到hadoop/lib下也没有起作用,请问各位大神,这个问题是出在哪里呢?虽然是简单的classnotfound,但是需要的我导入了啊。。。自己琢磨好几天了,不过还没想通,先谢谢大家了
...全文
4891 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
SG90 2014-09-05
  • 打赏
  • 举报
回复
引用 4 楼 niaodanwangzi 的回复:
          FileOutputFormat.setOutputPath(job, new Path(args[1])) 你设定的reduce的输出格式是文本,应该是写文件了吧,使用hbase自带的工具TableMapReduceUtil.initTableReducerJob() 试一下。 搭车同问,我这边写hbase报了个错: Exception in thread "main" java.lang.RuntimeException: org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for blog_dest,,99999999999999 after 14 tries. 请问有大神知道怎么回事儿吗
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for tmp_order_not_closed,,99999999999999 after 10 tries. 主要原因是在client的机器这边,没有配置hbase集群的主机信息。简单的方法就是在/etc/hosts文件增加全部的节点IP信息,第二种就是使用DNS的方式。
SG90 2014-09-05
  • 打赏
  • 举报
回复
引用 4 楼 niaodanwangzi 的回复:
          FileOutputFormat.setOutputPath(job, new Path(args[1])) 你设定的reduce的输出格式是文本,应该是写文件了吧,使用hbase自带的工具TableMapReduceUtil.initTableReducerJob() 试一下。 搭车同问,我这边写hbase报了个错: Exception in thread "main" java.lang.RuntimeException: org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for blog_dest,,99999999999999 after 14 tries. 请问有大神知道怎么回事儿吗
这里有个类似的问题http://community.cloudera.com/t5/Storage-Random-Access-HDFS/org-apache-hadoop-hbase-client-NoServerForRegionException-Unable/td-p/9044
niaodanwangzi 2014-09-05
  • 打赏
  • 举报
回复
引用 6 楼 Imbyr 的回复:
[quote=引用 4 楼 niaodanwangzi 的回复:]           FileOutputFormat.setOutputPath(job, new Path(args[1])) 你设定的reduce的输出格式是文本,应该是写文件了吧,使用hbase自带的工具TableMapReduceUtil.initTableReducerJob() 试一下。 搭车同问,我这边写hbase报了个错: Exception in thread "main" java.lang.RuntimeException: org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for blog_dest,,99999999999999 after 14 tries. 请问有大神知道怎么回事儿吗
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for tmp_order_not_closed,,99999999999999 after 10 tries. 主要原因是在client的机器这边,没有配置hbase集群的主机信息。简单的方法就是在/etc/hosts文件增加全部的节点IP信息,第二种就是使用DNS的方式。[/quote] /etc/hosts里配置了所有的节点ip的,
niaodanwangzi 2014-09-04
  • 打赏
  • 举报
回复
          FileOutputFormat.setOutputPath(job, new Path(args[1])) 你设定的reduce的输出格式是文本,应该是写文件了吧,使用hbase自带的工具TableMapReduceUtil.initTableReducerJob() 试一下。 搭车同问,我这边写hbase报了个错: Exception in thread "main" java.lang.RuntimeException: org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for blog_dest,,99999999999999 after 14 tries. 请问有大神知道怎么回事儿吗
ihelper_foryou 2014-08-31
  • 打赏
  • 举报
回复
http://www.linuxidc.com/Linux/2012-06/63305.htm,推荐你看一下,希望能解决问题
summerhai 2014-08-31
  • 打赏
  • 举报
回复
引用 2 楼 ihelper_foryou 的回复:
http://www.linuxidc.com/Linux/2012-06/63305.htm,推荐你看一下,希望能解决问题
赞!!!! 但是现在的问题是,写入不了HBase。。请问大神知道问题在哪吗
summerhai 2014-08-30
  • 打赏
  • 举报
回复
提示报错就是在代码的第5行,public static Configuration cfg = HBaseConfiguration.create();这里,没有找到HBaseConfiguration这个类

20,811

社区成员

发帖
与我相关
我的任务
社区描述
Hadoop生态大数据交流社区,致力于有Hadoop,hive,Spark,Hbase,Flink,ClickHouse,Kafka,数据仓库,大数据集群运维技术分享和交流等。致力于收集优质的博客
社区管理员
  • 分布式计算/Hadoop社区
  • 涤生大数据
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧