sbt简单使用

在scala 和spark的学习研究中难免会用到sbt 工具,以下对sbt的使用做简要说明

sbt 的安装在本文中不做赘述,网上安装可以百度一大堆。以下简单说明sbt 的常用命令。

sbt 安装之后,注意配置sbt环境变量。

说明:sbt 命令同Linux的命令一样,支持tab键补全命令,如果匹配多个命令,则会显示命令列表,以供选择

sbt  常用命令

说明:命令输完回车运行后当窗口中出现">"提示符,则说明sbt 运行完成

  • 进入stb 控制台(cmd 等命令窗口)
$ sbt
[info] Loading global plugins from C:\Users\Administrator\.sbt\0.13\plugins
[info] Loading project definition from E:\spark-jobserver\project
[info] Compiling 6 Scala sources to E:\spark-jobserver\project\target\scala-2.10\sbt-0.13\classes...
Missing bintray credentials C:\Users\Administrator\.bintray\.credentials. Some bintray features depend on this.
Missing bintray credentials C:\Users\Administrator\.bintray\.credentials. Some bintray features depend on this.
Missing bintray credentials C:\Users\Administrator\.bintray\.credentials. Some bintray features depend on this.
Missing bintray credentials C:\Users\Administrator\.bintray\.credentials. Some bintray features depend on this.
Missing bintray credentials C:\Users\Administrator\.bintray\.credentials. Some bintray features depend on this.
Missing bintray credentials C:\Users\Administrator\.bintray\.credentials. Some bintray features depend on this.
Missing bintray credentials C:\Users\Administrator\.bintray\.credentials. Some bintray features depend on this.
[info] Set current project to root (in build file:/E:/spark-jobserver/)
>

 

  • 列出所有任务(tasks)
> tasks

This is a list of tasks defined for the current project.
It does not list the scopes the tasks are defined in; use the 'inspect' command for that.
Tasks produce values.  Use the 'show' command to run the task and print the resulting value.

  clean            Deletes files produced by the build, such as generated sources, compiled classes, and task caches.
  compile          Compiles sources.
  console          Starts the Scala interpreter with the project classes on the classpath.
  consoleProject   Starts the Scala interpreter with the sbt and the build definition on the classpath and useful imports.
  consoleQuick     Starts the Scala interpreter with the project dependencies on the classpath.
  copyResources    Copies resources to the output directory.
  doc              Generates API documentation.
  ls               Search for remote libraries
  lsDocs           Launch library documentation
  package          Produces the main artifact, such as a binary jar.  This is typically an alias for the task that actually does the packaging.
  packageBin       Produces a main artifact, such as a binary jar.
  packageDoc       Produces a documentation artifact, such as a jar containing API documentation.
  packageSrc       Produces a source artifact, such as a jar containing sources and resources.
  publish          Publishes artifacts to a repository.
  publishLocal     Publishes artifacts to the local Ivy repository.
  publishM2        Publishes artifacts to the local Maven repository.
  reStart          Starts the application in a forked JVM (in the background). If it is already running the application is first stopped and then restarted.
  run              Runs a main class, passing along arguments provided on the command line.
  runMain          Runs the main class selected by the first argument, passing the remaining arguments to the main method.
  scalastyle       Run scalastyle on your code
  test             Executes all tests.
  testOnly         Executes the tests provided as arguments or all tests if no arguments are provided.
  testQuick        Executes the tests that either failed before, were not run or whose transitive dependencies changed, among those provided as arguments.
  update           Resolves and optionally retrieves dependencies, producing a report.

More tasks may be viewed by increasing verbosity.  See 'help tasks'.

>
  • 删除target目录下�编译生成的文件(clean)
sbt:HelloWorld> clean
[success] Total time: 1 s, completed 2019-1-31 15:45:04
sbt:HelloWorld>
  • 编译(compile):sbt是增量编译
sbt:HelloWorld> compile
[info] Updating ...
[info] Done updating.
[success] Total time: 1 s, completed 2019-1-31 15:46:01
sbt:HelloWorld>
  • 运行(run):run依赖于compile,所以会先执行compile,然后执行main方法(如果有多个,会提示要求选择一个执行)
sbt:HelloWorld> run
[info] Packaging E:\advance\bigdata\spark\HelloWorld\target\scala-2.12\helloworld_2.12-0.1.jar ...
[info] Done packaging.
[info] Running T
hello world ....
[success] Total time: 2 s, completed 2019-1-31 15:51:57
sbt:HelloWorld>
  • 运行测试用例(test)
sbt:HelloWorld> test
[success] Total time: 1 s, completed 2019-1-31 15:52:32
sbt:HelloWorld>
  • 更新外部依赖
sbt:HelloWorld> update
[info] Updating ...
[info] Done updating.
[success] Total time: 1 s, completed 2019-1-31 15:53:12
sbt:HelloWorld>
  • 更新工程配置(reload)
sbt:HelloWorld> reload
[info] Loading project definition from E:\HelloWorld\project
[info] Loading settings for project helloworld from build.sbt ...
[info] Set current project to HelloWorld (in build file:/E:/HelloWorld/)
sbt:HelloWorld>
  • 查看工程配置   方法一:(name)
sbt:HelloWorld> name
[info] HelloWorld
sbt:HelloWorld>
  • 查看工程配置   方法二:(inspect)
sbt:HelloWorld> inspect version
[info] Setting: java.lang.String = 0.1
[info] Description:
[info]  The version/revision of the current module.
[info] Provided by:
[info]  ProjectRef(uri("file:/E:/HelloWorld/"), "helloworld") / version
[info] Defined at:
[info]  E:\HelloWorld\build.sbt:3
[info] Reverse dependencies:
[info]  projectID
[info]  isSnapshot
[info] Delegates:
[info]  version
[info]  ThisBuild / version
[info]  Global / version
[info] Related:
[info]  Global / version
sbt:HelloWorld>
  • 编译并进入REPL
sbt:HelloWorld> console
[info] Starting scala interpreter...
Welcome to Scala 2.12.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_144).
Type in expressions for evaluation. Or try :help.

scala> print
print   printf   println

scala> print
   def print(x: Any): Unit

scala> println("haha")
haha

scala> :quit

[success] Total time: 43 s, completed 2019-1-31 15:59:15
sbt:HelloWorld>
  • 自动编译(~compile)
sbt:HelloWorld> ~compile
[success] Total time: 0 s, completed 2019-1-31 16:00:03
1. Waiting for source changes in project helloworld... (press enter to interrupt)
sbt:HelloWorld>
  • 退出shell(exit)

 

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值