请先自行安装scala
本次教程使用scala 2.11.12
sbt的安装配置
- 下载sbt-1.5.3.tgz
http://www.scala-sbt.org/download.html
- 到下载目录下执行以下命令
tar zxvf sbt-0.13.5.tgz
sudo mv sb /usr/local/
- 建立sbt可执行文件
/*选定一个位置,建立启动sbt的脚本文本文件,如/usr/local/sbt/ 目录下面新建文件名为sbt的文本文件*/
$ cd /usr/local/sbt/
$ vim sbt
/*在sbt文本文件中添加
SBT_OPTS="-Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M"
java $SBT_OPTS -jar /usr/local/sbt/bin/sbt-launch.jar "$@"
然后按esc键 输入 :wq 保存退出,注意红色字体中的路径是定位到解压的sbt文件包中的sbt-launch.jar文件的绝对路径*/
/×修改sbt文件权限×/
$ chmod u+x sbt
- 配置path环境变量,以保证可以使用sbt命令台
$ vim ~/.bashrc
/*在文件尾部添加如下代码后,保存退出*/
export PATH=/usr/local/sbt/:$PATH
/*使配置文件立刻生效*/
$ source ~/.bashrc
- 测试是否安装成功
/*第一次执行时,会下载一些文件包,然后才能正常使用,要确保联网了,安装成功后显示如下*/
$ sbt
OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=256M; support was removed in 8.0
[info] welcome to sbt 1.5.3 (Private Build Java 1.8.0_292)
[info] loading global plugins from /home/trf/.sbt/1.0/plugins
[info] loading project definition from /home/trf/project
[info] set current project to trf (in build file:/home/trf/)
[info] sbt server started at local:///home/trf/.sbt/1.0/server/9e83e5bece8687f24356/sock
[info] started sbt server
7.更换镜像源,输入vim ~/.sbt/repositories 来修改文件如下:
[repositories]
local
aliyun: http://maven.aliyun.com/nexus/content/groups/public/
central: http://repo1.maven.org/maven2/
- 打开IDEA,找到:
File | Settings | Build, Execution, Deployment | Build Tools | sbt 配置Maximum heap size, MB为1536 VM parameters为:-Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled 然后launcher选择custom并选择我们的sbt-lauch.jar 9.测试sbt是否成功:点击New | Project创建一个scala的sbt项目 10.我们测试加载config以及scalatest依赖,修改build.sbt内容如下并重新load即可。
name := "scala_test"
version := "0.1"
scalaVersion := "2.11.12"
libraryDependencies += "com.typesafe" % "config" % "1.4.0"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.3"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.3" % "test"
|