gpt4 book ai didi

java - 如何通过 Maven 在 Intellij 中导入 hadoop.hbase.mapreduce?

转载 作者:可可西里 更新时间:2023-11-01 16:36:07 27 4
gpt4 key购买 nike

我打算在IntelliJ中使用Hadoop的伪分布式模式。目前,我可以在笔记本电脑上成功运行 WordCount 示例代码。然后,我尝试编写另一个代码,其中包括 hbase 的用法。但是,我无法在我的代码中导入 import org.apache.hadoop.hbase.mapreduce.TableReducer;。我试图添加不同的 Maven 依赖项,但它不起作用。

这是 hadoop 代码:

package topten;

import java.io.*;
import java.util.Map;
import java.util.TreeMap;
import java.util.HashMap;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter;

public class TopTen {

public static class TopTenMapper extends Mapper<Object, Text, NullWritable, Text> {
// Stores a map of user reputation to the record
TreeMap<Integer, Text> repToRecordMap = new TreeMap<Integer, Text>();

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
//<FILL IN>
}

protected void cleanup(Context context) throws IOException, InterruptedException {
// Output our ten records to the reducers with a null key
//<FILL IN>
}
}

public static class TopTenReducer extends TableReducer<NullWritable, Text, NullWritable> {
// Stores a map of user reputation to the record
private TreeMap<Integer, Text> repToRecordMap = new TreeMap<Integer, Text>();

public void reduce(NullWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
//<FILL IN>
}
}

public static void main(String[] args) throws Exception {
}
}

这是我的maven配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.dataintensivecomputing</groupId>
<artifactId>hadoop</artifactId>
<version>1.0-SNAPSHOT</version>

<repositories>
<repository>
<id>apache</id>
<url>http://maven.apache.org</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-server</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-common</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-mapreduce</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
</project>

谁能告诉我应该将哪些 Maven 依赖项添加到 pom.xml 文件中?

最佳答案

根据 Github 源代码,这对于几个版本的 HBase 都是正确的

    <dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-mapreduce</artifactId>
<version>${hbase.version}</version>
</dependency>

不清楚您运行的 Hbase + Hadoop 的实际版本,但您确实应该使它们在您的 POM 中保持一致

<properties>
<hadoop.version>2.7.2</hadoop.version>
<hbase.version>2.1.0</hbase.version>
<properties>

现在,将这些属性用于每个依赖项的相同 group.id,然后运行 ​​mvn clean compile,如果类有导入问题,应该不会有任何导入问题事实上存在。

您还可以为 IntelliJ 启用自动导入

关于java - 如何通过 Maven 在 Intellij 中导入 hadoop.hbase.mapreduce?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52303597/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com