首页 文章

带有Scala插件,Maven和Spark的Eclipse项目

提问于
浏览
0

我有Eclipse Kepler,我已经安装了Maven和Scala插件 . 我创建一个新的Maven项目并添加依赖项

groupId:org.apache.spark artifactId:spark-core_2.10 version:1.1.0

根据http://spark.apache.org/downloads.html的当前文档,一切都很好,Scala 2.10的 jar 也被添加到项目中 . 然后我将"Scala Nature"添加到项目中,这会添加Scala 2.11,我最终得到以下错误

在构建路径中找到了多个scala库(C:/Eclipse/eclipse-jee-kepler-SR2-win32-x86_64/plugins/org.scala-lang.scala-library_2.11.2.v20140721-095018-73fb460c1c.jar, C:/Users/fff/.m2/repository/org/scala-lang/scala-library/2.10.4/scala-library-2.10.4.jar) . 至少有一个版本具有不兼容的版本 . 请更新项目构建路径,使其仅包含兼容的scala库 .

是否可以将Spark(来自Maven)和Scala IDE插件一起使用?关于如何解决这个问题的任何想法?

谢谢你的帮助 . 问候

5 回答

  • 2

    简而言之,是的,这是可能的 .

    Spark目前正在使用Scala 2.10,而最新的Scala IDE则是2.10和2.11的“交叉发布” . 您需要选择基于2.10的版本,即3.0.3 .

    但是,处于候选发布模式的下一个主要版本4.0具有多版本支持 . 您可以创建Scala项目并选择您要使用的Scala版本(2.10或2.11) . 如果您愿意,可以尝试一下 .

  • 0

    如果有人在搜索相同的东西时偶然发现:

    我最近创建了Maven原型,用于使用Scala 2.10.4项目引导新的Spark 1.3.0 . 按照这里的说明:https://github.com/spark-in-action/scala-archetype-sparkinaction

    对于IntelliJ IDEA,首先从命令行生成项目,然后导入IDE .

  • 0

    您已经安装了Scala Ide插件,但只有在项目中包含scala类时,项目的Scala才有用 . 然而,Spark和Scala是一起工作的 . 确保使用兼容版本 . 您可以在计算机上install scala,然后使用兼容的spark maven依赖项 .

  • 1

    是的,你可以..使用我在下面提供的pom

    <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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.spark-scala</groupId>
        <artifactId>spark-scala</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>${project.artifactId}</name>
        <description>Spark in Scala</description>
        <inceptionYear>2010</inceptionYear>
    
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <encoding>UTF-8</encoding>
            <scala.tools.version>2.10</scala.tools.version>
            <!-- Put the Scala version of the cluster -->
            <scala.version>2.10.4</scala.version>
        </properties>
    
        <!-- repository to add org.apache.spark -->
        <repositories>
            <repository>
                <id>cloudera-repo-releases</id>
                <url>https://repository.cloudera.com/artifactory/repo/</url>
            </repository>
        </repositories>
    
        <build>
            <sourceDirectory>src/main/scala</sourceDirectory>
            <testSourceDirectory>src/test/scala</testSourceDirectory>
            <plugins>
                <plugin>
                    <!-- see http://davidb.github.com/scala-maven-plugin -->
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                    <version>3.2.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.13</version>
                    <configuration>
                        <useFile>false</useFile>
                        <disableXmlReport>true</disableXmlReport>
                        <includes>
                            <include>**/*Test.*</include>
                            <include>**/*Suite.*</include>
                        </includes>
                    </configuration>
                </plugin>
    
                <!-- "package" command plugin -->
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4.1</version>
                    <configuration>
                        <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>
                <plugin>
                    <groupId>org.scala-tools</groupId>
                    <artifactId>maven-scala-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
        <dependencies>
            <dependency>
                <groupId>org.apache.spark</groupId>
                <artifactId>spark-core_2.11</artifactId>
                <version>1.2.1</version>
            </dependency>
        </dependencies>
    </project>
    
  • 0

    有两种类型的Spark JAR文件(只需查看名称):

    • 名称包含单词“assembly”而不是“core”(里面有Scala)

    • 名称包含单词“core”而不是“assembly”(内部没有Scala) .

    您应该通过“添加外部JAR”(您需要的版本)在Build Path中包含“核心”类型,因为Scala IDE已经为您推送了一个Scala .

    或者,您可以利用SBT并添加以下依赖项(再次注意您需要的版本):

    libraryDependencies =“org.apache.spark”%“spark-core_2.11”%“2.1.0”

    那么你不应该在Build Path中“强制”包含任何spark JAR .

    快乐的火花:

    扎尔

相关问题