MRUnit Maven 项目导入问题

MRUnit Maven project import issue

我正在研究 O'Really "Hadoop, the definitive guide 4th edition" 一书中的 Hadoop,我在尝试创建用于 MRUnit 测试的 Maven 项目时遇到问题。我刚刚创建了书中所示的 pom.xml 文件(只是更改了我的 hadoop 版本),但它不起作用,Eclipse 让我看到了很多 ArtifactTransferExceptions.

我的 pom.xml 看起来像这样:

<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>TestUnitCounter</groupId>
   <artifactId>TestUnitCounter</artifactId>
   <version>4.0</version>
<properties>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <hadoop.version>2.6.0</hadoop.version>
</properties>
<dependencies>
<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-client</artifactId>
    <version>${hadoop.version}</version>
</dependency>

<!-- Unit test artifacts -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.apache.mrunit</groupId>
    <artifactId>mrunit</artifactId>
    <version>1.1.0</version>
    <classifier>hadoop2</classifier>
    <scope>test</scope>
</dependency>

<!-- Hadoop test artifact for running mini clusters -->
<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-minicluster</artifactId>
    <version>${hadoop.version}</version>
    <scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>hadoop-examples</finalName>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.5</version>
        <configuration>
            <outputDirectory>${basedir}</outputDirectory>
        </configuration>
  </plugin>
</plugins>
</build>
</project>

有人可以告诉我如何解决这个问题并为此编写正确的 pom.xml 吗?

谢谢。

您可以尝试以下步骤:

1) 使用以下命令删除所有失败的下载:

Unix 平台

find ~/.m2  -name "*.lastUpdated" -exec grep -q "Could not transfer" {} \; -print -exec rm {} \;

Windows 平台

cd %userprofile%\.m2\repository
for /r %i in (*.lastUpdated) do del %i

2) 现在,在 eclipse 中右键单击您的项目并选择 Maven-> Update Dependencies(Select 复选框 Force Update Snapshots/Releases), OK.