出于某种原因,我在尝试使用Cassandra作为Hadoop的输入时遇到以下异常
Exception in thread "main" java.lang.NoClassDefFoundError: com/datastax/driver/core/policies/LoadBalancingPolicy
这是代码
public class CDriver extends Configured implements Tool{
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException, Exception
{
Configuration conf = new Configuration();
ToolRunner.run(new CDriver(), args);
}
@Override
public int run(String[] args) throws Exception {
String output = args[0];
Configuration conf = super.getConf();
Job job = new Job(conf);
job.setJarByClass(CDriver.class);
job.setJobName("Cassandra as input");
ConfigHelper.setInputInitialAddress(conf, "127.0.0.1");
ConfigHelper.setInputColumnFamily(conf, "basketball", "nba");
ConfigHelper.setInputPartitioner(conf, "Murmur3Partitioner");
CqlConfigHelper.setInputCQLPageRowSize(conf, "3");
job.setInputFormatClass(CqlInputFormat.class);
FileOutputFormat.setOutputPath(job, new Path(output));
job.setMapperClass(CMapper.class);
job.setReducerClass(CReducer.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.waitForCompletion(true);
return 0;
}
}
以下一行
CqlConfigHelper.setInputCQLPageRowSize(conf, "3");
以下是Maven依赖项:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nissatech</groupId>
<artifactId>TestingCassandra</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>2.1.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.nissatech.testingcassandra.CDriver</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
任何人都可以解释是什么问题?我让Cassandra在localhost上运行。
答案 0 :(得分:0)
您还需要在pom.xml
中包含Datastax Java驱动程序作为第三方依赖项。见https://github.com/datastax/java-driver#maven。如果你将它作为传递依赖,请确保使用正确的版本。