初始SBT,搭建scala环境采坑
SBT版本: 1.3.4
Scala版本:2.12.10
操作系统: Windows
分别下载SBT的Scala进行安装。
安装完SBT到D:\sbt目录后,配置D:\sbt\conf下的repo.properties和sbtconfig.txt
repo.properties的内容如下
[repositories]
local
aliyun-central: https://maven.aliyun.com/repository/central
aliyun-public: https://maven.aliyun.com/repository/public
jcenter: https://jcenter.bintray.com/
repo1: https://repo1.maven.org/maven2/
store_2: http://repo2.maven.org/maven2/
aliyun-releases: https://maven.aliyun.com/repository/releases
aliyun-apache-snapshots: https://maven.aliyun.com/repository/apache-snapshots
aliyun-google: https://maven.aliyun.com/repository/google
aliyun-jcenter: https://maven.aliyun.com/repository/jcenter
aliyun-spring: https://maven.aliyun.com/repository/spring
aliyun-spring-plugin: https://maven.aliyun.com/repository/spring-plugin
sbt-plugin: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/
sonatype: http://oss.sonatype.org/content/repositories/snapshots
typesafe: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
typesafe2: http://repo.typesafe.com/typesafe/releases/
atlassian: https://packages.atlassian.com/content/repositories/atlassian-public/
spring-plugin: https://repo.spring.io/plugins-release/
hortonworks: https://repo.hortonworks.com/content/repositories/releases/
Repostory的url来源于maven仓库, 冒号前面的名字自己起,如阿里的仓库。 sbt找一个jar,会逐个遍历仓库,直到找到为止,所以要把常用的下载速度快的放在前面。
sbtconfig.txt的内容如下:
# 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.boot.directory=D:/sbt/boot/
-Dsbt.global.base=D:/sbt/.sbt
-Dsbt.ivy.home=D:/sbt/.ivy2
-Dsbt.repository.config=D:/sbt/conf/repo.properties
-Dsbt.override.build.repos=true
第一次执行sbt命令的时候(如sbt new scala/hello-world.g8),会下载一堆堆的依赖,慢。
可以参考 GETTING STARTED WITH SCALA AND SBT ON THE COMMAND LINE
日志文件是 D:\sbt\boot\update.log
下载的各依赖包会放在 D:\sbt\.ivy2\cache目录下。如果下载依赖包的时候挂住了,Ctrl C结束命令,再重新执行命令
如果遇到了下面的错误
[error] java.lang.NoClassDefFoundError: okio/Source
[error] Use 'last' for the full log.
或者
[error] java.lang.NoClassDefFoundError: kotlin/TypeCastException
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
去maven下载相应的jar包放在D:\sbt\boot\scala-2.12.10\org.scala-sbt\sbt\1.3.4目录下
在maven上搜okio和kotlin, 要下载的jar包是okio-2.4.1.jar和kotlin-stdlib-1.3.61.jar
在IDEA里面使用sbt创建scala项目,会dump project structure from sbt很久,key跟踪D:\sbt\boot\update.log看看是不是下载jar包的问题。
如果在Idea里使用sbt建立或导入项目也报NoClassDefFoundError错误,可以把D:\sbt\boot\scala-2.12.10\org.scala-sbt\sbt\1.3.4下jar包作为一个library导入到工程目录下。
上一篇: Ajax+asp.net实现用户登陆
推荐阅读