Intellij Idea Spark -线程“main”中出现异常java.lang.NoSuchMethodError:scala.reflect.api.JavaUniverse.runtimeMirror

oxosxuxt  于 2023-08-03  发布在  Spark
关注(0)|答案(3)|浏览(145)

我使用的是Scala 2.11.8,并使用maven在IntelliJ中构建jar文件
我在mobaxterm中运行了我的程序:

/opt/spark-1.6.1-bin-hadoop2.6/bin/spark-submit --class CDR.SQL cdr-maven-1.0-SNAPSHOT.jar

字符串
这是错误消息:
线程"main" java. lang. NoSuchMethodError:Scala. reflect. api. JavaUniverse. runtimeMirror(Ljava/lang/ClassLoader;)Lscala/reflect/api/JavaUniverse $JavaMirror;在CDR。SQL $。(SQL. scala:24)在CDR处。SQL $。(SQL. scala)处。main(SQL. scala)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.反思NativeMethodAccessorImpl.在sun调用(NativeMethodAccessorImpl.java:62)。反思DelegatingMethodAccessorImpl.在java中调用(DelegatingMethodAccessorImpl.java:43)。lang。反思方法。在org调用(Method.java:498)。ApacheSpark部署SparkSubmit $. org $apache $spark $deploy $SparkSubmit $$runMain(SparkSubmit. scala:731)at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit. scala:181)在org.ApacheSpark部署SparkSubmit $.提交(SparkSubmit. scala:206)在org.ApacheSpark部署SparkSubmit $. main(SparkSubmit. scala:121)在org.ApacheSpark部署SparkSubmit。main(SparkSubmit. scala)
这是我的pom.xml文件:

<?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>cdr-maven</groupId>
    <artifactId>cdr-maven</artifactId>
    <version>1.0-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>apache-repo</id>
            <name>Apache Repository</name>
            <url>https://repository.apache.org/content/repositories/releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>2.15.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-mllib_2.11</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-sql_2.11</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-hive_2.11</artifactId>
            <version>1.4.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-streaming_2.11</artifactId>
            <version>1.4.1</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

</project>


我该如何解决这个问题?
谢谢你的帮助!

f87krz0w

f87krz0w1#

你下载了Spark发行版还是自己构建的?
Spark 1.6是默认使用Scala 2.10构建的。请将Scala版本更改为2.10或将Spark更新为2.0,默认情况下,Spark是使用Scala 2.11构建的

mzillmmw

mzillmmw2#

将Scala版本更改为2.12.12。这解决了我的问题。还要注意spark核心和spark sql版本应该相同
Mine POM.xml

<?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.ravitutorial.example</groupId>
    <artifactId>SparkProject</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
        <encoding>UTF-8</encoding>
        <scala.tools.version>2.12</scala.tools.version>
        **<scala.version>2.12.12</scala.version>**
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core was 2.3.1 update to 2.4.2 -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_${scala.tools.version}</artifactId>
            <version>3.3.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-sql_${scala.tools.version}</artifactId>
            <version>3.3.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.databricks/spark-avro -->
        <dependency>
            <groupId>com.databricks</groupId>
            <artifactId>spark-avro_2.11</artifactId>
            <version>4.0.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.esotericsoftware.kryo/kryo -->
        <dependency>
            <groupId>com.esotericsoftware.kryo</groupId>
            <artifactId>kryo</artifactId>
            <version>2.24.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.38</version>
        </dependency>

        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.delta/delta-core -->
        <dependency>
            <groupId>io.delta</groupId>
            <artifactId>delta-core_${scala.tools.version}</artifactId>
            <version>2.2.0</version>
        </dependency>

    </dependencies>

</project>

字符串

slhcrj9b

slhcrj9b3#

检查版本。

<build>
    <plugins>
        <plugin>
            <groupId>org.scala-tools</groupId>
            <artifactId>maven-scala-plugin</artifactId>
            <version>2.15.2</version>
            <executions>
                <execution>

字符串
您使用的是2.15.x版本。

相关问题