sbt编程语言scala的构建工具配置及项目构建(附带网盘下载)

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

SBT简介

SBT 是 Scala 的构建工具全称是 Simple Build Tool 类似 Maven 或 Gradle。

Java可以用Maven快速构建项目scala用SBT快速构建一个Scala项目。

sbt下载官网

百度网盘链接https://pan.baidu.com/s/1eJkdWndZ0izcd3waqA2hdQ
提取码oeq1

在这里插入图片描述

SBT参数配置

配置本地目录

在config的该目录下追加内容

在这里插入图片描述

-Dsbt.log.format=true
-Dfile.encoding=UTF8
-Dsbt.global.base=e:/sbt/.sbt
-Dsbt.boot.directory=e:/sbt/.sbt/boot/
-Dsbt.repository.config=e:/sbt/.sbt/repo.properties
-Dsbt.ivy.home=e:/sbt/.ivy2
-Dsbt.override.build.repos=true
-Xmx512M
-Xss2M
-XX:+CMSClassUnloadingEnabled

有路径的设置为本地路径即可

设置阿里镜像新建repo.properties

新建的目录要和上面配置的对应

[repositories]
local
aliyun: http://maven.aliyun.com/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

java.io.IOException: failed to create lock file e:\Scala\sbt-1.7.2\repo\boot\sbt.boot.lock

java.io.IOException: failed to create lock file e:\Scala\sbt-1.7.2\repo\boot\sbt.boot.lock
        at xsbt.boot.Locks$.liftedTree1$1(Locks.scala:43)
        at xsbt.boot.Locks$.apply0(Locks.scala:41)
        at xsbt.boot.Locks$.apply(Locks.scala:36)
        at xsbt.boot.Launch.locked(Launch.scala:393)
        at xsbt.boot.Launch.getAppProvider(Launch.scala:304)
        at xsbt.boot.Launch.app(Launch.scala:216)
        at xsbt.boot.Launch.app(Launch.scala:214)
        at xsbt.boot.Launch$.run(Launch.scala:140)
        at xsbt.boot.Launch$.$anonfun$apply$1(Launch.scala:44)
        at xsbt.boot.Launch$.launch(Launch.scala:159)
        at xsbt.boot.Launch$.apply(Launch.scala:44)
        at xsbt.boot.Launch$.apply(Launch.scala:21)
        at xsbt.boot.Boot$.runImpl(Boot.scala:78)
        at xsbt.boot.Boot$.run(Boot.scala:73)
        at xsbt.boot.Boot$.main(Boot.scala:21)
        at xsbt.boot.Boot.main(Boot.scala)
Caused by: java.io.IOException: 系统找不到指定的路径。
        at java.io.WinNTFileSystem.createFileExclusively(Native Method)
        at java.io.File.createNewFile(File.java:1012)
        at xsbt.boot.Locks$.liftedTree1$1(Locks.scala:41)
        ... 15 more
[error] [launcher] error during sbt launcher: java.io.IOException: failed to create lock file e:\Scala\sbt-1.7.2\repo\boot\sbt.boot.lock

Dsbt.repository.config=e:/sbt/.sbt/repo.properties在本地设置时/是在Linux系统的路径在window中要使用\。例如本地配置

# 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:\Scala\sbt-1.7.2\repo\base
-Dsbt.boot.directory=d:\Scala\sbt-1.7.2\repo\boot
-Dsbt.repository.config=d:\Scala\sbt-1.7.2\repo\repo.properties
-Dsbt.ivy.home=d:\Scala\sbt-1.7.2\repo\.ivy2
-Dsbt.override.build.repos=true

出现该错误都是路径问题未找到路径或路径配置不对注意修改

安装完成测试

  • 若sbt配置了环境变量直接在dos下输入sbt
  • 未配置环境变量在sbt的bin目录下输入sbt

在这里插入图片描述>出现上面界面即配置完成

IDEA 基于scala插件构建项目

基于IDEA的创建方式需要全局配置sbt即配置环境变量。
在这里插入图片描述
之后版本选择与版本对应就行了

在这里插入图片描述

第一次加载时间会很长切换为阿里镜像会快一点

找到用户资料的文件夹下的.sbt文件夹

在这里插入图片描述
创建repo.properties文件:

[repositories]
local
Nexus osc : http://maven.oschina.net/content/groups/public/
Nexus osc thirdparty : http://maven.oschina.net/content/repositories/thirdparty/
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/
sbt-plugin: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/
sonatype: http://oss.sonatype.org/content/repositories/snapshots
uk_maven: http://uk.maven.org/maven2/
ibibli: http://mirrors.ibiblio.org/maven2/
repo2: http://repo2.maven.org/maven2/

基于Maven构建

打开设置中的项目结构
打开项目结构选择全局库点击+号导入下载的scala文件scala.zip解压的文件夹是scala-sdk
在这里插入图片描述

导完后应该是上图所示的样子

再新建选择Maven-----------------》选择从原型构建----------》------------》scala-archtype-simple

在这里插入图片描述

下一步
在这里插入图片描述
maven配置

在这里插入图片描述

IDEA创建scala项目的三种方法

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6