线程main中的异常:classnotfoundexception

vddsk6oq  于 2021-06-04  发布在  Hadoop
关注(0)|答案(1)|浏览(296)

我在学校群里运行hadoop。我在线程主线程中得到异常,类未找到异常。

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个小时,任何帮助表示感谢。

rqcrx0a6

rqcrx0a61#

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

相关问题