gpt4 book ai didi

java - Thread Main 中的异常 : ClassNotFoundException

转载 作者:可可西里 更新时间:2023-11-01 14:58:58 26 4
gpt4 key购买 nike

我在学校集群中运行 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 个小时里,对错误的搜索一直令人沮丧,我们将不胜感激任何帮助。

最佳答案

您可以尝试“libjar”选项,它将获取 jar 并将其放置在分布式缓存中。这使得 jar 可用于作业的所有任务尝试。请注意,libjars 参数采用逗号分隔列表,而不是冒号或分号分隔列表。

export LIBJARS=/path/jars1,/path/jars2,/path/movielens.jar

hadoop jar movielens.jar movielens.MovieLensDriver -libjars ${LIBJARS} 输入输出

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com