Scala是一门以Java虚拟机(JVM) 为运行环境并将面向对象和函数式编程的最佳特性结合在一起的静态类型编程语言
Scala是一门多范式的编程语言, Scala支持面向对象和函数式编程。 (多范式, 就是多种编程方法的意思。 有面向过程、 面向对象、 泛型、 函数式四种程序设计方法
Scala源代码(.scala) 会被编译成Java字节码(.class) , 然后运行于JVM之上, 并可以调用现有的Java类库, 实现两种语言的无缝对接。
scala环境搭建 sbt管理项目sbt的配置,参考sbt官方文档
下载安装sbt,https://www.scala-sbt.org/download.html
目录结构如下
D:\sbt>tree
├── bin
│ ├── sbt
│ ├── sbt.bat
│ ├── sbt-launch.jar
│ └── sbtn-x86_64-pc-win32.exe
├── conf
│ ├── repo.properties
│ ├── sbtconfig.txt
│ └── sbtopts
├── LICENSE
└── NOTICE
sbt-launcher.jar
是一个自包含的jar文件,只需要配置文件和jre>1.6,可以直接用压缩包方式打开为 sbt 注入适当的 boot.properties 文件,启动器初始化会拉取boot文件
sbt启动器配置
[scala]
version: ${sbt.scala.version-auto}
[app]
org: ${sbt.organization-org.scala-sbt}
name: sbt
version: ${sbt.version-read(sbt.version)[1.6.2]}
class: ${sbt.main.class-sbt.xMain}
components: xsbti,extra
cross-versioned: ${sbt.cross.versioned-false}
resources: ${sbt.extraClasspath-}
[repositories]
local
maven-central
sbt-maven-releases: https://repo.scala-sbt.org/scalasbt/maven-releases/, bootOnly
[boot]
directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}
lock: ${sbt.boot.lock-true}
[ivy]
ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}
checksums: ${sbt.checksums-sha1,md5}
override-build-repos: ${sbt.override.build.repos-false}
repository-config: ${sbt.repository.config-${sbt.global.base-${user.home}/.sbt}/repositories}
进入安装目录的conf配置sbtconfig.txt
,等于是不用注入launch.jar了
# sbt configuration file for Windows
# Set the java args
#-mem 1024 was added in sbt.bat as default
#-Xms1024m
#-Xmx1024m
#-Xss4M
#-XX:ReservedCodeCacheSize=128m
# Set the extra sbt options
# -Dsbt.log.format=true
-Dsbt.log.format=true
-Dfile.encoding=UTF8
-Dsbt.global.base=d:/sbt/.sbt
-Dsbt.boot.directory=d:/sbt/.sbt/boot/
-Dsbt.repository.config=d:/sbt/.sbt/repo.properties
#jar的存放地址
-Dsbt.ivy.home=d:/sbt/.ivy
#采用全局配置
-Dsbt.override.build.repos=true
-Xmx512M
-Xss2M
-XX:+CMSClassUnloadingEnabled
此外,可以在 ~/.sbt 路径下创建repositories文件,配置镜像源
[repositories]
local
maven-local
aliyun: https://maven.aliyun.com/repository/public
typesafe: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
ivy-sbt-plugin:https://dl.bintray.com/sbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
sonatype-oss-releases
maven-central
sonatype-oss-snapshots
在idea安装scala插件,这个插件会自动下载sbt-launch.jar所以实际上可以不用安装sbt
配置sbt为本地sbt
将scala的sdk加载到project structure中
sbt折腾了好久,但是idea始终还是把依赖文件下载到Appdata中,不是很明白为什么,准备用maven来做要简单很多
libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "2.1.0"
libraryDependencies += "org.apache.hbase" % "hbase-client" % "1.1.2"
libraryDependencies += "org.apache.hbase" % "hbase-common" % "1.1.2"
libraryDependencies += "org.apache.hbase" % "hbase-server" % "1.1.2"
libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.2.0"
libraryDependencies += "mysql" % "mysql-connector-java" % "8.0.15"
maven管理项目
maven比较简单,直接创建maven项目添加scala支持
创建scala源码文件夹
比起sbt很简单,开始code吧
参考:
- https://zhuanlan.zhihu.com/p/82727108
- https://blog.csdn.net/weixin_43495317/article/details/103889448
- https://blog.csdn.net/a295567172/article/details/78456069
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)