eclipse+scala+spark+maven的配置

1. 首先通过菜单的Help选中Eclipse Marketplace,出现如下界面:


再Find框中输入Scala,会出来Scala IDE插件,安装这个插件,就可以在eclipse上使用scala编写程序了。

2. 点击Help中的Install New Software,出来如下图,点击Add按钮添加url: http://alchim31.net/m2e-scala/update-site,name自己取。出来下图中的Maven Integration for Eclipse,选中所有到next步骤。

3.安装完成后,可去Help->Installation Details查看。


至此,eclipse可以用maven管理scala项目了。

4.  添加Spark依赖:

在pom.xml中添加依赖:

 <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core_2.11 -->
<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-core_2.11</artifactId>
    <version>2.1.1</version>
</dependency>

note: spark-core后面的2.11指的是scala的版本。

5. 错误:

在配置完eclipse+scala+maven的时候出现错误not found: type JUnitRunner,这个主要是因为缺少specs2-junit jar包引起的,在pom.xml中添加依赖:

<!-- https://mvnrepository.com/artifact/org.specs2/specs2-junit_2.11 -->
<dependency>
    <groupId>org.specs2</groupId>
    <artifactId>specs2-junit_2.11</artifactId>
    <version>3.8.9</version>
    <scope>test</scope>
</dependency>

即可。

6.奉上我的pom.xml

<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>org.qiuqiu</groupId>
  <artifactId>scala</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>${project.artifactId}</name>
  <description>My wonderfull scala app</description>
  <inceptionYear>2015</inceptionYear>
  <licenses>
    <license>
      <name>My License</name>
      <url>http://....</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <properties>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
    <encoding>UTF-8</encoding>
    <scala.version>2.11.5</scala.version>
    <scala.compat.version>2.11</scala.compat.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala.version}</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core_2.11 -->
<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-core_2.11</artifactId>
    <version>2.1.1</version>
   
</dependency>
    

    <!-- Test -->
  <!-- https://mvnrepository.com/artifact/junit/junit -->
		<dependency>
		    <groupId>junit</groupId>
		    <artifactId>junit</artifactId>
		    <version>4.8.1</version>
		    <scope>test</scope>
		</dependency>

   <!-- https://mvnrepository.com/artifact/org.specs2/specs2-core_2.11 -->
	<dependency>
	    <groupId>org.specs2</groupId>
	    <artifactId>specs2-core_2.11</artifactId>
	    <version>3.8.4</version>
	    <scope>test</scope>
	</dependency>
	<!-- https://mvnrepository.com/artifact/org.specs2/specs2-junit_2.11 -->
<dependency>
    <groupId>org.specs2</groupId>
    <artifactId>specs2-junit_2.11</artifactId>
    <version>3.8.9</version>
    <scope>test</scope>
</dependency>

   
    <dependency>
      <groupId>org.scalatest</groupId>
      <artifactId>scalatest_${scala.compat.version}</artifactId>
      <version>2.2.4</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/junit/junit -->
	
    
  </dependencies>

  <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.0</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <args>
                <arg>-make:transitive</arg>
                <arg>-dependencyfile</arg>
                <arg>${project.build.directory}/.scala_dependencies</arg>
              </args>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <configuration>
          <useFile>false</useFile>
          <disableXmlReport>true</disableXmlReport>
          <!-- If you have classpath issue like NoDefClassError,... -->
          <!-- useManifestOnlyJar>false</useManifestOnlyJar -->
          <includes>
            <include>**/*Test.*</include>
            <include>**/*Suite.*</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是搭建idea+maven+spark+scala项目的步骤: 1. 安装JDK和Scala环境。 2. 安装Maven。 3. 在IDEA中创建Maven项目。 4. 在pom.xml文件中添加依赖,包括SparkScala相关依赖。 5. 在src/main/scala目录下创建Scala文件。 6. 编写Spark程序。 7. 运行程序。 具体步骤如下: 1. 安装JDK和Scala环境 首先需要安装Java开发工具包(JDK),并配置环境变量。然后安装Scala编程语言,同样也需要配置环境变量。可以参考官网的安装说明进行操作。 2. 安装Maven Maven是一个Java项目管理工具,可以自动下载所需的依赖库,并将项目打包成Jar包。可以从官网下载Maven,并配置环境变量。 3. 在IDEA中创建Maven项目 在IDEA中创建Maven项目,选择Scala模板,填写项目名称、groupId、artifactId等信息。IDEA会自动生成pom.xml文件。 4. 在pom.xml文件中添加依赖 在pom.xml文件中添加SparkScala相关依赖,例如: ``` <dependencies> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-core_2.11</artifactId> <version>2.4.5</version> </dependency> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-sql_2.11</artifactId> <version>2.4.5</version> </dependency> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>2.11.8</version> </dependency> </dependencies> ``` 5. 在src/main/scala目录下创建Scala文件 在src/main/scala目录下创建Scala文件,例如: ``` object Test { def main(args: Array[String]) { val conf = new SparkConf().setAppName("Test").setMaster("local[*]") val sc = new SparkContext(conf) val sqlContext = new SQLContext(sc) val df = sqlContext.read.json("data/people.json") df.show() } } ``` 6. 编写Spark程序 在Scala文件中编写Spark程序,例如读取JSON文件并显示数据。 7. 运行程序 在IDEA中运行程序,即可看到Spark程序的输出结果。 以上就是搭建idea+maven+spark+scala项目的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值