我有一个网页,当我从页面中选择一个选项时,它会调用servlet并执行twitter分析查询。但我得到了例外 java.lang.NoClassDefFoundError:org / apache / spark / SparkConf
请在下面找到我的代码
public static void Top8UsersTweetsCount()
{
SparkConf conf = new SparkConf().setAppName("User mining").setMaster("local[*]");
JavaSparkContext sc = new JavaSparkContext(conf);
JavaSQLContext sqlContext = new JavaSQLContext(sc);
JavaSchemaRDD tweets = sqlContext.jsonFile(pathToFile);
tweets.registerAsTable("tweetTable");
tweets.printSchema();
nbTweetByUser(sqlContext);
sc.stop();
}
private static void nbTweetByUser(JavaSQLContext sqlContext)
{
try
{
FileWriter fw= new FileWriter("C:/Users/ashok/PBPhase2/TwitterAnalysis/WebContent/query2.csv");
JavaSchemaRDD count = sqlContext.sql("SELECT user.name,user.statuses_count AS c FROM tweetTable " +
"ORDER BY c");
List<org.apache.spark.sql.api.java.Row> rows = count.collect();
Collections.reverse(rows);
String rows123=rows.toString();
String[] array = rows123.split("],");
System.out.println(rows123);
fw.append("Name");
fw.append(',');
fw.append("Count");
fw.append("\n");
for(int i = 0; i < 8; i++)
{
if(i==0)
{
fw.append(array[0].substring(2));
fw.append(',');
fw.append("\n");
}
else {
fw.append(array[i].substring(2));
fw.append(',');
fw.append("\n");
}
}
fw.close();
}
catch (Exception exp)
{
}
}
错误:
java.lang.NoClassDefFoundError: org/apache/spark/SparkConf
at Query1.UserNamesHavingmorethan600000Friends(Query1.java:447)
at Query1.doPost(Query1.java:82)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1275)
at [internal classes]
答案 0 :(得分:0)
检查您的项目工件。如果您使用 Ant ,则必须将 Apache-Spark 库添加到容器( Tomcat )工件中。