使用sbt,idea 创建 scala 工程,记录一下
1、安装sbt,配置使用其他镜像地址
windows 7 环境
下载地址:https://www.scala-sbt.org/download.html
安装位置:D:\sbt
(安装成功后,sbt运行环境地址,D:\sbt\bin,一般会自动添加到环境变量中)
如果不修改默认配置,使用默认镜像,则下载环境依赖的jar包,会很慢,基本是失败;
打开 D:\sbt\conf\sbtconfig.txt,添加如下内容:
-Dsbt.log.format=true
-Dsbt.boot.directory=D:/sbt/.sbt/boot
-Dsbt.ivy.home=D:/sbt/.ivy2
-Dsbt.global.base=D:/sbt/.sbt
-Dsbt.repository.config=D:/sbt/conf/repository.properties
在D:\sbt\conf目录中,创建 repository.properties 文件,添加如下内容:
[repositories]
local
aliyun-nexus: http://maven.aliyun.com/nexus/content/groups/public/
ibiblio-maven: http://maven.ibiblio.org/maven2/
typesafe-ivy: https://dl.bintray.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
uk-repository: http://uk.maven.org/maven2/
jboss-repository: http://repository.jboss.org/nexus/content/groups/public/
typesafe: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
sonatype-oss-releases
maven-central
sonatype-oss-snapshots
【 还有aliyun的另外一个地址:
aliyun-nexus: http://maven.aliyun.com/nexus/content/repositories/central/
我在使用的过程中,发现环境依赖的包,多数是从ibiblio-maven,uk-repository中下载的 】
创建scala工程目录,比如:F:\scala
命令行进入,输入:sbt new scala/hello-world.g8
第一次运行,会下载很多依赖包,需要等待较长时间;
接着,下载工程模板,如下所示:
进入工程目录hello-world,输入:sbt (会下载依赖的jar包)
输入:run 运行工程
2、IDEA,创建scala工程,使用独立安装的sbt环境;
首先安装idea scala插件;
配置,使用1步骤中,已经安装的sbt环境;
- 但是可能是版本原因,配置的本地仓库并没有生效,jar还是下载到了C盘,在查找资料后,发现还有另一个地方需要配置。
D:\javaTool\sbt\bin\sbt-launch.jar
配置文件是在D:\javaTool\sbt\bin\sbt-launch.jar中的\sbt\sbt.boot.properties中(可用rar解压工具直接打开修改并覆盖,记住是用rar打开文件不需要解压,否则弄不回jar了),修改里面的内容:
[scala]
version: ${sbt.scala.version-auto}
[app]
org: ${sbt.organization-org.scala-sbt}
name: sbt
version: ${sbt.version-read(sbt.version)[1.1.6]}
class: ${sbt.main.class-sbt.xMain}
components: xsbti,extra
cross-versioned: ${sbt.cross.versioned-false}
resources: ${sbt.extraClasspath-}
[repositories]
local
spring: http://conjars.org/repo/
cloudera: https://repository.cloudera.com/artifactory/cloudera-repos/
aliyun: http://maven.aliyun.com/nexus/content/groups/public/
maven-central
sbt-maven-releases: https://repo.scala-sbt.org/scalasbt/maven-releases/, bootOnly
sbt-maven-snapshots: https://repo.scala-sbt.org/scalasbt/maven-snapshots/, bootOnly
typesafe-ivy-releases: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
sbt-ivy-snapshots: https://repo.scala-sbt.org/scalasbt/ivy-snapshots/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
[boot]
directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}
lock: ${sbt.boot.lock-true}
[ivy]
ivy-home: D:/javaTool/sbt/ivy
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}