0

I can execute java program by build it with maven on hadoop-cluster.

source-code of my program

package com.ait.summer.clusterermapreduce;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.mahout.clustering.canopy.CanopyDriver;
import org.apache.mahout.clustering.kmeans.KMeansDriver;
import org.apache.mahout.common.HadoopUtil;
import org.apache.mahout.common.distance.EuclideanDistanceMeasure;

public class ClustererMapReduce {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {

        Configuration conf = new Configuration();
        FileSystem hdfs = FileSystem.get(conf);

        Path ProjectFolder = new Path (args[0]);

        Path InputDir = new Path(args[0], "in");
        Path OutputDir = new Path(args[0], "out");
        Path canopyCentroids = new Path(args[0], "canopyCentroids");
        HadoopUtil.delete(conf, OutputDir);

        double clusterClassificationThreshold = 0.5;
        double t1 = 20;
        double t2 = 30;
                // how to set up correctly param?

        CanopyDriver.run(conf, InputDir, canopyCentroids, new EuclideanDistanceMeasure(),
                t1, t2, false, clusterClassificationThreshold, false);        

        KMeansDriver.run(conf, InputDir, new Path(canopyCentroids, "clusters-0"), OutputDir, new EuclideanDistanceMeasure(), 0.5 , 5, true, 0.5 , false);

    }
}

my pom.xml file

<?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.ait.summer</groupId>
    <artifactId>ClustererMapReduce</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <repositories>
    <repository>
      <id>apache.snapshots</id>
      <name>Apache Snapshot Repository</name>
      <url>http://repository.apache.org/snapshots</url>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>

    <repository>
      <id>cdh.repo</id>
      <url>https://repository.cloudera.com/artifactory/cloudera-repos</url>
      <name>Cloudera Repositories</name>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>

    <repository>
      <id>cdh.snapshots.repo</id>
      <url>https://repository.cloudera.com/artifactory/libs-snapshot-local</url>
      <name>Cloudera Snapshots Repository</name>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>
  </repositories>
    <dependencies>

        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.0.0-cdh4.7.0</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.apache.mahout</groupId>
            <artifactId>mahout-core</artifactId>
            <version>0.7-cdh4.7.0</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>1.0.8a</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
</project>

after compiling this code from command line (i situated in project dir)

$ mvn install

I run it with

$ hadoop jar

and received this error-log

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/mahout/common/distance/DistanceMeasure
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:201)
Caused by: java.lang.ClassNotFoundException: org.apache.mahout.common.distance.DistanceMeasure
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 3 more

I use CDH-4.7.0 JDK 1.7.0.65 use NetBeans IDE 8.0

What might be cause of this problem?

1 Answers1

0

If you've created the JAR with maven, you can run the following command:

In Linux: export CLASSPATH=<path_jars_dependencies and jar_ClustererMapReduce> java -cp $CLASSPATH com.ait.summer.clusterermapreduce.ClustererMapReduce

[path_jars_dependencies]: You can export the dependencies of your application using the post: How can I create an executable JAR with dependencies using Maven?

[jar_ClustererMapReduce]: It's the JAR generated with the command maven install

Community
  • 1
  • 1
salmuz
  • 44
  • 1
  • 3