前言
要开发Scala
程序, 一般使用的IDE
主要有3种:
- NetBean
- Eclipse
- IDEA
由于个人不太习惯IDEA
的一些使用功能, 已经只能打开一个项目.(这可太蠢了.)
所以, 继续选择在Eclipse IDE
上集成Scala IDE
. 当然, 官方提供了Scala IDE
, 可以直接使用. 但是, 如果你之前哟一个版本的Eclipse
的话, 个人建议还是升级比较好.
基础知识
关于Eclipse 插件的安装和卸载
建议看下我的这篇文章Eclipse 插件管理.
基本操作
主要安装2项东西: scala-IDE
与m2e-scala模版
.
Scala IDE
可以选择离线安装与在线安装.
-
在线安装(市场安装)
注意:Eclipse
有的版本没有这个, 你可以选择离线安装.
-
在线安装 选择地址(Oxgen):
http://download.scala-ide.org/sdk/lithium/e47/scala212/stable/site
注意: 相应版本的插件地址, 建议官网查看一下.
-
离线安装: http://scala-ide.org/download/prev-stable.html
解压压缩包, 随后安装即可.
-
安装
m2e-scala
在Maven
项目内识别scala
程序. 下载地址:
http://alchim31.free.fr/m2e-scala/update-site/
-
在线安装(同上 输入
m2e-scala
/http://alchim31.free.fr/m2e-scala/update-site/
)
这个地址国内被墙了, 而且貌似jar
包名字多一个空格.(真坑) -
离线安装(同上
Scala-IDE
)
我已经上传到CSDN
上了, 当然你也可以翻墙将上面的东西下载下来. 离线安装即可.
Scala
环境配置
- 选择适合的
Scala版本
- 配置
Scala
到build path
.
- 测试程序运行
创建Hello.scala
, 运行.
object Hello2 {
def main(args: Array[String]): Unit = {
println("123")
}
}
注意, 如果没有Run as Scala Application
. 原因有2个:
Scala-IDE
插件配置错误;- 代码或包错误.
另: 官方的这个操作教学视频还可以, 大家有兴趣可以看看. 相关地址: http://scala-ide.org/download/current.html
Others
代码补齐报错.An internal error occurred during: "Computing additional info"
.
解决办法: 更换版本 / 不使用代码补全功能.(这个问题非常恶心)
[10]. eclipse安装Scala IDE插件及An internal error occurred during: "Computing additional info"报错解决
Maven
在使用模版创建完成后, 发现并不好用. Scala
使用的依赖类库需要跟随自己的使用进行升级.
# 原版
<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.yanxml</groupId>
<artifactId>quick-scala</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>My wonderfull scala app</description>
<inceptionYear>2010</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.tools.version>2.10</scala.tools.version>
<scala.version>2.10.0</scala.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2_${scala.tools.version}</artifactId>
<version>1.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.tools.version}</artifactId>
<version>2.0.M6-SNAP8</version>
<scope>test</scope>
</dependency>
</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.1.3</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.13</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>
# 更新版本
<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.yanxml</groupId>
<artifactId>quick-scala</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>My wonderfull scala app</description>
<inceptionYear>2010</inceptionYear>
<licenses>
<license>
<name>My License</name>
<url>http://....</url>
<distribution>repo</distribution>
</license>
</licenses>
<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.11</scala.tools.version>
<scala.version>2.11.8</scala.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.8</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.11.8</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-reflect</artifactId>
<version>2.11.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.scala-lang/scala-actors -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-actors</artifactId>
<version>2.11.8</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- <dependency> <groupId>org.specs2</groupId> <artifactId>specs2_${scala.tools.version}</artifactId>
<version>3.0</version> <scope>test</scope> </dependency> -->
<!-- https://mvnrepository.com/artifact/org.scalatest/scalatest -->
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.11</artifactId>
<version>3.0.0-M16-SNAP6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.tools.version}</artifactId>
<version>3.0.0-M16-SNAP6</version>
<scope>test</scope>
</dependency>
<!-- spark -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.2.1</version>
</dependency>
<!-- akka -->
<!-- https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor -->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<version>2.3.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.typesafe.akka/akka-remote -->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-remote_2.11</artifactId>
<version>2.3.14</version>
</dependency>
</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.1.3</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.13</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>
Q1:
Description Resource Path Location Type missing or invalid dependency detected while loading class file 'JsonBaseMatchers.class'. Could not access term parsing in package scala.util, because it (or its dependencies) are missing. Check your build definition for missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) A full rebuild may help if 'JsonBaseMatchers.class' was compiled against an incompatible version of scala.util. (NOTE: It looks like the scala-parser-combinators module is missing; try adding a dependency on "org.scala-lang.modules" : "scala-parser-combinators". See http://docs.scala-lang.org/overviews/ for more information.) quick-scala Unknown Scala Problem
A1: 更新Maven依赖类库的版本.
scala-eclipse-maven环境搭建
Q2: Eclipse 内无法读取Scala源码. 无法解决! 这个问题是为什么那么多人无奈选择
IDEA
的原因. 至于其他的部分源码, 可以使用反编译工具. 个人感觉可以内嵌Scala
反编译工具到Eclipse里面即可.(感觉个人有兴趣,可以开发一个.)
- 在eclipse中添加jdk源码
- eclipse 关联源码的两种方式
- spark最新源码下载并导入到开发环境下助推高质量代码(Scala IDEA for Eclipse和IntelliJ IDEA皆适用)(以spark2.2.0源码包为例)(图文详解)
- attaching-sources-in-intellij-idea-for-scala-project
- intellij idea查看scala sdk的源代码
- Eclipse安装反编译插件
- MyEclipse中android 项目如何解决第三方jar无法关联源码的问题( The JAR of this class file belongs to container ‘Android Private Libraries’ which does not allow modifications to source attachments on its entries.
- running-spark-on-eclipse-in-linux
- importing-spark-source-code-to-eclipse-ide
- 用Eclipse开发Spark应用,如何跟踪Spark源代码
- eclipse不识别scala代码
- Eclipse中如何关联源码?
- scala ide for eclipse搭建spark源码阅读环境报错
- Eclipse中Maven引入依赖后自动下载并关联源码(Source)
Reference
[1]. Offical - Scala IDE
[2]. Offical - m2e-scala
[3]. eclipse安装scala环境
[4]. 在eclipse中如何配置运行Scala?
[5]. eclipse安装scala
[6]. 分别用Eclipse和IDEA搭建Scala+Spark开发环境
[7]. maven插件(3) - scala插件scala-maven-plugin
[8]. Scala之——Eclipse离线手动安装Scala插件
[9]. There is “Run Configuration” but no “Run As Scala Application” in Eclipse
[10]. eclipse安装Scala IDE插件及An internal error occurred during: "Computing additional info"报错解决
[11]. 编写代码时,每打一个字符就会弹出“Computing additional info”.Could not initialize class…