简体   繁体   中英

java.lang.NoClassDefFoundError: org/apache/spark/SparkConf

I Have a web page, when I select an option from page, It will call servlet and execute the twitter analysis queries. But I got the exception java.lang.NoClassDefFoundError: org/apache/spark/SparkConf

Please find my code below

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)
          {
          }

      }

Error :

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]

Check your project artifact. If you use Ant then Apache-Spark library must be added to container( Tomcat ) artifact.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM