我正在学校集群中运行hadoop。我在线程main中收到异常,但未找到类。

Exception in thread "main" java.lang.ClassNotFoundException: movielens.MovieLensDriver
    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:423)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:153)

但是我知道我必须在命令中使用完整的程序包名称,并且我已经做了同样的事情。以下是我使用的命令
hadoop jar movielens.jar movielens.MovieLensDriver input output

以下是我的驱动程序类的代码。
package movielens;

import java.io.IOException;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.KeyValueTextInputFormat;
import org.apache.hadoop.mapred.jobcontrol.Job;
import org.apache.hadoop.mapred.jobcontrol.JobControl;

public class MovieLensDriver {

    public static class JobRunner implements Runnable {
        private JobControl control;

        public JobRunner(JobControl _control) {
            this.control = _control;
        }

        public void run() {
            this.control.run();
        }
    }

    public static void handleRun(JobControl control)
            throws InterruptedException {
        JobRunner runner = new JobRunner(control);
        Thread t = new Thread(runner);
        t.start();

        while (!control.allFinished()) {
            System.out.println("Still running...");
            Thread.sleep(5000);
        }
    }

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

        System.out.println("Program started");
        if (args.length != 2) {
            System.err
                    .println("Usage: MovieLensDriver <input path> <output path>");
            System.exit(-1);
        }

        JobConf conf1 = new JobConf(movielens.MovieLensDriver.class);
        conf1.setMapperClass(MoviePairsMapper.class);
        conf1.setReducerClass(MoviePairsReducer.class);

        conf1.setJarByClass(MovieLensDriver.class);

        FileInputFormat.addInputPath(conf1, new Path(args[0]));
        FileOutputFormat.setOutputPath(conf1, new Path("temp"));

        conf1.setMapOutputKeyClass(Text.class);
        conf1.setMapOutputValueClass(Text.class);

        conf1.setOutputKeyClass(Text.class);
        conf1.setOutputValueClass(IntWritable.class);

        JobConf conf2 = new JobConf(MovieLensDriver.class);
        conf2.setMapperClass(MoviePairsCoOccurMapper.class);
        conf2.setReducerClass(MoviePairsCoOccurReducer.class);

        conf2.setJarByClass(MovieLensDriver.class);

        FileInputFormat.addInputPath(conf2, new Path("temp"));
        FileOutputFormat.setOutputPath(conf2, new Path(args[1]));

        conf2.setInputFormat(KeyValueTextInputFormat.class);

        conf2.setMapOutputKeyClass(Text.class);
        conf2.setMapOutputValueClass(IntWritable.class);

        conf2.setOutputKeyClass(Text.class);
        conf2.setOutputValueClass(IntWritable.class);

        Job job1 = new Job(conf1);
        Job job2 = new Job(conf2);

        JobControl jobControl = new JobControl("jobControl");
        jobControl.addJob(job1);
        jobControl.addJob(job2);
        job2.addDependingJob(job1);
        handleRun(jobControl);

        System.out.println("Program complete.");

        System.exit(0);
    }
}

最近3个小时以来,对该错误的搜索一直令人沮丧,我们非常感谢您的帮助。

最佳答案

您可以尝试使用“libjar”选项,该选项将使用jar并将其放置在分布式缓存中。这使jar可以用于所有作业的任务尝试。请注意,libjars参数采用逗号分隔的列表,而不是用冒号或分号分隔的列表。
export LIBJARS=/path/jars1,/path/jars2,/path/movielens.jarhadoop jar movielens.jar movielens.MovieLensDriver -libjars ${LIBJARS} input output

关于java - 线程Main中的异常:ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22430866/

10-13 03:47