Search code examples
javaclasspathjavacmahoutcloudera

Mahout Java compilation issue


I am reading Mahout in Action and working through the first example in chapter 2.

$ javac RecommenderIntro.java 
RecommenderIntro.java:2: error: package org.apache.mahout.cf.taste.impl.model.file does not exist
import org.apache.mahout.cf.taste.impl.model.file.*;
^
RecommenderIntro.java:3: error: package org.apache.mahout.cf.taste.impl.neighborhood does not exist
import org.apache.mahout.cf.taste.impl.neighborhood.*;
^
RecommenderIntro.java:4: error: package org.apache.mahout.cf.taste.impl.recommender does not exist
import org.apache.mahout.cf.taste.impl.recommender.*;

I installed Mahout via yum:

$ sudo yum install mahout
...
Downloading Packages:
mahout-0.7+12-1.cdh4.2.0.p0.9.el6.noarch.rpm                      |  94 MB     05:17     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating   : mahout-0.7+12-1.cdh4.2.0.p0.9.el6.noarch              1/2 
Cleanup    : mahout-0.7+8-1.cdh4.1.2.p0.12.el6.noarch              2/2 
Verifying  : mahout-0.7+12-1.cdh4.2.0.p0.9.el6.noarch              1/2 
Verifying  : mahout-0.7+8-1.cdh4.1.2.p0.12.el6.noarch              2/2 

Updated:
mahout.noarch 0:0.7+12-1.cdh4.2.0.p0.9.el6                                                             

Complete!

I am also completely brand new to Java.

Am I compiling this incorrectly?

Do I need to specify some include paths on the command line with invoking javac?


Solution

  • So it turns out this is simple, once you know where the jars you need are located. In the cloudera mahout distribution they are in /usr/lib/mahout and /usr/lib/mahout/lib.

    $ javac -cp "/usr/lib/mahout/*:/usr/lib/mahout/lib/*:." RecommenderIntro.java 
    $ java -cp "/usr/lib/mahout/*:/usr/lib/mahout/lib/*:." RecommenderIntro 
    
    RecommendedItem[item:104, value:4.257081]