本文介绍了NoClassDefFound:Scala/xml/元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Java运行一个简单的spark程序(IDE:Eclipse Luna,Maven).

I'm running a simple spark program in Java (IDE : Eclipse Luna, Maven).

我的示例程序是

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext;

public class testSpark {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf().setAppName("Testing").setMaster("local");
        JavaSparkContext sc = new JavaSparkContext(conf);

        System.out.println(sc.appName());
    }
}

但是在运行示例程序时出现错误

But I'm getting error while running my sample program

起因: java.lang.ClassNotFoundException:scala.xml.MetaData位于 java.net.URLClassLoader.findClass(未知源),网址为 java.lang.ClassLoader.loadClass(未知来源)

Caused by: java.lang.ClassNotFoundException: scala.xml.MetaData at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source)

我的pom.xml文件是

My pom.xml file is

<dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-mllib_2.11</artifactId>
            <version>1.2.1</version>
        </dependency>

推荐答案

SparkUI似乎使用了scala包,请尝试将此dsependency添加到pom文件中,以将scala.xml包放在类路径中.

SparkUI seems to use a scala package, try adding this dsependency to your pom file to put the scala.xml package on your classpath.

<dependency>
    <groupId>org.scala-lang</groupId>
    <artifactId>scala-xml</artifactId>
    <version>2.11.0-M4</version>
</dependency>

这篇关于NoClassDefFound:Scala/xml/元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 17:06