Running Kmeans Clustering example with Maven (Mahout in Action)

Home / Uncategorized / Running Kmeans Clustering example with Maven (Mahout in Action)

Question:
I’m considering the same example as in How to run examples in mahout in action book, but I want to use Maven to run it. It builds fine with
> mvn clean -DskipTests package
but when I try to run it:> 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
This is strange, since I included mahout-math-0.7 in my pom.xml, and I manually checked that it includes Vector.class. So what’s going wrong? Do I need to use hadoop rather than java, or is there something wrong with my pom.xml? I’m assuming that having http://maven.apache.org is fine if I’m pulling from http://mvnrepository.com/ …

For reference, here’s what I have in my pom.xml:
4.0.0
Clustering
K-Means jar 1.0-SNAPSHOT
K-Means
http://maven.apache.org


junit
junit
3.8.1
test


org.apache.mahout
mahout-mr
0.10.0


org.apache.mahout
mahout-core
0.7


org.apache.mahout
mahout-math
0.7

And here are my imports: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;


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *