繁体   English   中英

找不到Hadoop映射器类

[英]Hadoop mapper class not found

我已经使用Apache Hadoop 1.2.1开发了一个map-reduce程序。 我使用Eclipse IDE进行了初始开发,以模拟hadoop分布式计算环境,其中所有输入和输出文件都来自本地文件系统。 该程序将在Eclipse中执行,不会有任何问题。 然后,我使用Eclipse创建一个JAR文件,并尝试在我的一台hadoop集群上运行此文件并收到错误:

这是我设置和运行hadoop作业的代码:

String outputPath = "/output";
String hadoopInstructionsPath = args[0];

Job job = new Job();
job.setJarByClass(Main.class);  //setJarByClass is here but not found apparently?!?
job.setJobName("KLSH");

FileInputFormat.addInputPath(job, new Path(hadoopInstructionsPath));
FileOutputFormat.setOutputPath(job,new Path(outputPath));


job.setMapperClass(KLSHMapper.class);
job.setReducerClass(KLSHReducer.class);

job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);

System.exit(job.waitForCompletion(true) ? 0:1);
boolean success = job.waitForCompletion(true);
return success ? 0 : 1;

然后,使用eclipse使用File-> Export-> Runnable JAR文件创建一个jar,以创建要在集群上运行的JAR文件。

我用来运行作业的命令如下(KLSH.jar是JAR文件的名称,/ hadoopInstruction是args [0]输入参数,imageFeature.Main /指定主类的位置)

./hadoop jar ./KLSH.jar /hadoopInstructions imageFeatures.Main/

这将产生以下输出:

14/11/12 11:11:48 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
14/11/12 11:11:48 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
14/11/12 11:11:48 INFO input.FileInputFormat: Total input paths to process : 1
14/11/12 11:11:48 INFO util.NativeCodeLoader: Loaded the native-hadoop library
14/11/12 11:11:48 WARN snappy.LoadSnappy: Snappy native library not loaded
14/11/12 11:11:49 INFO mapred.JobClient: Running job: job_201411051030_0022
14/11/12 11:11:50 INFO mapred.JobClient:  map 0% reduce 0%
14/11/12 11:11:56 INFO mapred.JobClient: Task Id : attempt_201411051030_0022_m_000000_0, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: imageFeatures.KLSHMapper
...

因此它出错了,因为它找不到映射器类。 没有“未设置作业jar文件集”警告,但是我觉得我已经在第一段代码中指定了job.setJarByClass,所以我不知道为什么会抛出此错误...

我也知道KLSHMapper类在JAR中,因为如果运行以下命令,则:

jar tf KLSH.jar

我得到了很多输出,但这是输出的一部分:

...
imageFeatures/Main.class
imageFeatures/Feature.class
imageFeatures/FileLoader.class
imageFeatures/KLSHMapper.class
...

因此,显然KLSHMapper类在其中...我试图修改我的hadoop类路径以包括KLSH.jar路径,我试图将KLSH.jar复制到DFS上并尝试使用该路径而不是路径我的本地文件系统,并且我还尝试使用-libjars说明符执行作业。 无论我如何尝试,hadoop似乎都无法找到我的Mapper类。 外面有人可以指出我在做错什么吗? 从在Eclipse中工作的代码到在实际的Hadoop集群上工作,我似乎无法跳脱。 谢谢!

您的文件中是否有导入语句:

import imageFeatures.KLSHMapper;

您还需要在CLASSPATH环境变量中包含包含imageFeatures.KLSMapper的jar文件。 这是非常奇怪的外来代码,您可能已经在这里了,所以也许我离这很遥远...

经过一些额外的工作,我能够解决自己的问题。 最终,归结为我构建jar文件的方式,然后尝试在hadoop集群上执行该文件。

我没有使用eclipse来构建JAR文件,而是从命令行使用Maven来构建JAR文件。 在pom.xml文件中,可以通过使用以下几行来指定主类:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <mainClass>maxTemp.MaxTemperature</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

就我而言,maxTemp是程序包,MaxTemperature是包含我的主要方法的类。 这将导致maven为您构建的JAR中包含的清单文件添加以下行:

Main-Class: maxTemp.MaxTemperature

现在,当您使用hadoop执行jar文件时,您将不再需要指定mainClass,因为您已经在jar的清单中指定了MainClass。 如果JAR清单中没有此行,则需要使用以下语法在集群上执行作业:

./hadoop jarFile [mainClass] args...

使用清单文件中的这一行,您可以按照以下步骤执行作业:

./hadoop jarFile args...

顺便说一句,并且有些相关,我遇到了一些问题,因为我使用的是jeigen java库来做一些线性代数。 我的集群无法找到我曾经使用过的依赖项(jeigen.jar),并且抛出了更多错误。 我最终建立了一个胖子罐,如本网站所述:

http://hadoopi.wordpress.com/2014/06/05/hadoop-add-third-party-libraries-to-mapreduce-job/

通过对pom.xml文件进行一些添加,我能够生成具有依赖项的maxTemp-jar-jar,然后集群能够找到我的所有依赖项,因为它们都包含在jar文件中。 我希望这可以帮助将来节省一些时间。 其中一些依赖项位于我的本地系统上,而Maven则无法获取它们。 我能够使用它们指向maven并手动安装它们:

mvn install:install-file -DgroupId=jeigen -DartifactId=jeigen -Dversion=1 -Dpackaging=jar -Dfile=/path/to/the/location/of/Jeigen.jar

这是我的pom.xml文件,该文件生成两个jar,一个包含有,另一个不包含依赖项:

<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>maxTemp</groupId>
  <artifactId>maxTemp</artifactId>
  <version>0.0.1</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>

      <plugin>
        <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>
        <configuration>
          <archive>
            <manifest>
              <mainClass>maxTemp.MaxTemperature</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
          <configuration>
            <archive>
              <manifest>
                <mainClass>maxTemp.MaxTemperature</mainClass>
              </manifest>
            </archive>
            <descriptorRefs>
              <descriptorRef>
                jar-with-dependencies
              </descriptorRef>
            </descriptorRefs>
          </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
  <dependencies>

    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-client</artifactId>
      <version>1.2.1</version>
    </dependency>

    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-core</artifactId>
      <version>1.2.1</version>
    </dependency>

    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-tools</artifactId>
      <version>1.2.1</version>
    </dependency>

    <dependency>
      <groupId>jeigen</groupId>
      <artifactId>jeigen</artifactId>
      <version>1</version>
    </dependency>

    <dependency>
      <groupId>jna</groupId>
      <artifactId>jna</artifactId>
      <version>4.0.0</version>
    </dependency>

  </dependencies>
</project>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM