1

我是 Hadoop 的新手。昨天照着书,用JUnit作为气象数据的相应单元测试。但是出现了一些问题。

这是我的 pom 文件:

<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-common</artifactId>
        <version>2.9.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-hdfs</artifactId>
        <version>2.9.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.mrunit</groupId>
        <artifactId>mrunit</artifactId>
        <version>1.1.0</version>
        <classifier>hadoop2</classifier>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-minicluster</artifactId>
        <version>2.9.0</version>
        <scope>test</scope>
    </dependency>
  </dependencies>

</project>

这是问题:

java.lang.IncompatibleClassChangeError:找到类 org.apache.hadoop.mapreduce.TaskInputOutputContext,但需要接口

期待并感谢您的回答!</p>

4

2 回答 2

0

尝试添加不同的 jar 版本。
我将 from 更改mrunit-1.1.0.jarmrunit-0.9.0-incubating-hadoop2.jar OLD JAR:- public interface Mapper<K1, V1, K2, V2> extends JobConfigurable, Closeable { }NEW JAR:-

 public class Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> {} 

我只是将 jar 从 hadoop1 更改为 hadoop2,之后我的所有单元测试用例都成功运行。 https://issues.apache.org/jira/browse/MRUNIT-156

     <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.org</groupId>
    <artifactId>com.org</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <dependencies>
        <!-- JDK Tools -->
        <dependency>
            <groupId>jdk.tools</groupId>
            <artifactId>jdk.tools</artifactId>
            <scope>system</scope>
            <version>1.8.0_73</version>
            <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
        </dependency>
        <!-- Hadoop Core -->
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-core</artifactId>
            <version>1.2.1</version>
        </dependency>
        <!-- Hadoop Mapreduce Client Core -->
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-mapreduce-client-core</artifactId>
            <version>2.7.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.mrunit</groupId>
            <artifactId>mrunit</artifactId>
            <version>0.9.0-incubating</version>
            <classifier>hadoop1</classifier>
        </dependency>
        <dependency>
            <groupId>org.apache.mrunit</groupId>
            <artifactId>mrunit</artifactId>
            <version>0.9.0-incubating</version>
            <classifier>hadoop2</classifier>
        </dependency>

    </dependencies>

</project>
于 2018-07-16T05:56:11.333 回答
0

我刚刚发现在 Hadoop 2.x 中,没有 Hadoop-core,所以正确的 pom 是:

<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-common</artifactId>
    <version>2.9.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-mapreduce-client-core</artifactId>
    <version>2.9.0</version>
</dependency>
<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-hdfs</artifactId>
    <version>2.9.0</version>
</dependency>
<dependency>
    <groupId>org.apache.mrunit</groupId>
    <artifactId>mrunit</artifactId>
    <version>1.1.0</version>
    <classifier>hadoop2</classifier>
    <scope>test</scope>
</dependency>
于 2018-07-18T08:07:28.217 回答