使用Maven运行Kmeans群集示例(Mahout in Action)

时间:2017-08-15 07:36:25

标签: maven cluster-analysis k-means mahout

我正在考虑与How to run examples in mahout in action book中相同的示例,但我想使用Maven来运行它。用

构建它很好
> mvn clean -DskipTests package

但是当我尝试运行它时:

> java -cp target/K-Means-1.0-SNAPSHOT.jar Clustering.Kmeans


Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: 
org/apache/mahout/math/Vector
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at 
sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at 
sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.mahout.math.Vector
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

这很奇怪,因为我在我的pom.xml中包含了mahout-math-0.7,并且我手动检查它是否包含Vector.class。那么出了什么问题?我需要使用hadoop而不是java,还是我的pom.xml有问题?我假设如果我从http://maven.apache.org拉出来http://mvnrepository.com/就好了{/ 3}}

供参考,这是我在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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Clustering</groupId>
<artifactId>K-Means</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>K-Means</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>

<dependency>
     <groupId>org.apache.mahout</groupId>
     <artifactId>mahout-mr</artifactId>
     <version>0.10.0</version>
</dependency>

    <dependency>
        <groupId>org.apache.mahout</groupId>
        <artifactId>mahout-core</artifactId>
        <version>0.7</version>
    </dependency>

    <dependency>
        <groupId>org.apache.mahout</groupId>
        <artifactId>mahout-math</artifactId>
        <version>0.7</version>
    </dependency>
</dependencies>
</project>

以下是我的进口商品:

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
import org.apache.mahout.clustering.Cluster;
import org.apache.mahout.clustering.classify.WeightedPropertyVectorWritable;
import org.apache.mahout.clustering.kmeans.KMeansDriver;
import org.apache.mahout.clustering.kmeans.Kluster;
import org.apache.mahout.common.distance.EuclideanDistanceMeasure;
import org.apache.mahout.math.RandomAccessSparseVector;
import org.apache.mahout.math.Vector;
import org.apache.mahout.math.VectorWritable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

1 个答案:

答案 0 :(得分:0)

你的类路径不包括所有的jar。

也不要混合版本。