`
lw9956164
  • 浏览: 27225 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
最近访客 更多访客>>
社区版块
存档分类
最新评论

A build tool for Scala(simple-build-tool) sbt安装指南

阅读更多

   今天有位写框架的大哥叫我学一学scalatra框架,找了半天没几个教程是可以用的。

今天晚上整理一下,下面有完整的连接哟。要使用scalatra进行web开发首先必须使用google的sbt。

我找文档找了好久啊,终于找到这篇文档了.特来跟大家分享一下!

Introduction

This page describes how to set up your project for use with sbt.

The basic steps are:

  1. Create a script to launch sbt.
  2. Create your project with sbt.
  3. Put libraries in lib and sources in src.
  4. Read RunningSbt for basic usage instructions.
  5. Read BuildConfiguration for further configuration.

Launching Sbt

The easiest way to launch sbt is to create a one-line script. Download sbt-launch.jar if you have not already.

Note: do not put sbt-launch.jar in your $SCALA_HOME/lib directory, your project's lib directory, or anywhere it will be put on a classpath.

Note: The encoding used by your terminal may differ from Java's default encoding for your platform. In this case, you will need to add the option -Dfile.encoding=<encoding> in the following scripts to set the encoding.

Unix

Put the jar in your ~/bin directory, put the line

java -Xmx512M -jar `dirname $0`/sbt-launch.jar "$@"

in a file called sbt in your ~/bin directory and do

$ chmod u+x ~/bin/sbt

This allows you to launch sbt in any directory by typing sbt at the command prompt.

sbt will pick up any HTTP proxy settings from the http.proxy environment variable. If you are behind a proxy requiring authentication, you must in addition pass flags to set the http.proxyUser and http.proxyPassword properties:

java -Dhttp.proxyUser=username -Dhttp.proxyPassword=mypassword -Xmx512M -jar `dirname $0`/sbt-launch.jar "$@"

Windows

Create a batch file sbt.bat:

set SCRIPT_DIR=%~dp0 
java
-Xmx512M -jar "%SCRIPT_DIR%sbt-launch.jar" %*

and put the jar in the same directory as the batch file. Put sbt.bat on your path so that you can launch sbt in any directory by typing sbt at the command prompt.

If you are behind a proxy on Windows, add flags to this second line for proxy host, port, and if applicable, username and password:

java -Dhttp.proxyHost=myproxy -Dhttp.proxyPort=8080 -Dhttp.proxyUser=username -Dhttp.proxyPassword=mypassword -Xmx512M -jar "%SCRIPT_DIR%sbt-launch.jar" %*

Create Project

Full Setup

When you run sbt and it does not find a project in the current directory, it asks if you want to create a new project. If you say yes, sbt will prompt for some basic information:

  • Project name: This name will be used in scaladocs and as part of the default name for generated packages.
  • Project organization: This is used for dependency management and is optional.
  • Project version: This is used in scaladocs, as part of the default name for generated packages, and for dependency management.
  • Scala version: This is version(s) of scala to build the project with. Multiple versions may be separated by spaces (see CrossBuild). Allowed values are (in theory) any version of Scala 2.7.2 or later available in the Scala Tools repository.
  • Sbt version: This is the version of sbt to build the project with. Currently, this should be 0.7.0, 0.7.1, 0.7.2, 0.7.3, or 0.7.4.

See Loader for more information on setting the versions of Scala and sbt to use to build your project. With the above information, sbt creates the project properties file and directory structure. These are described in the following section.

Quick Setup

In addition to 'yes' or 'no', you can type s (for scratch) when prompted to create a new project. This can be used to quickly get sbt compiling and running code without needing to do a full project setup. This option skips all of the prompts in a full setup and configures sbt to look in the current directory for sources and jars in addition to the usual places in a full project. Using sbt for a hello world might look like:

  $ echo 'object Hi { def main(args: Array[String]) { println("Hi!") } }' > hw.scala 
  $ sbt 
 
Project does not exist, create new project? (y/N/s) :
 
... 
 
> run 
 
... 
 
Hi!

Directory Layout

Sources

Sbt uses the same directory structure as Maven for source files by default (all paths are relative to the project directory):

  src/ 
    main
/ 
      resources
/ 
         
<files to include in main jar here> 
      scala
/ 
         
<main Scala sources> 
      java
/ 
         
<main Java sources> 
    test
/ 
      resources 
         
<files to include in test jar here> 
      scala
/ 
         
<test Scala sources> 
      java
/ 
         
<test Java sources>

Other directories in src/ will be ignored. Additionally, all hidden directories will be ignored.

Dependencies

All dependencies (jars) go in the

  lib/

directory or any subdirectory of lib. Again, hidden directories will be ignored. If you want to use ScalaCheck, specs, or ScalaTest for testing, those jars should go in here as well. Alternatively, you can configure sbt to automatically manage your dependencies (see LibraryManagement).

Build Configuration

Build configuration is done in the project directory:

  project/ 
    build
.properties 
    build
/ 
    boot
/

The build.properties file contains the project name, version, and organization, the versions of Scala and sbt used to build the project, and any other user-defined properties (see Properties). You can directly edit this file to change these properties or you can use the set command at the interactive prompt (see Basic Usage). The build directory is where further configuration is done and is described in BuildConfiguration. The boot directory is where the versions of Scala and sbt used to build the project are downloaded to.

Products

Generated files (classes, jars, analysis, and documentation) will be written to the

  target/

directory. Automatically managed dependencies are downloaded to:

  lib_managed/

Version Control

sbt creates and uses several directories that you will normally want to exclude from version control:

  target/ 
  lib_managed
/ 
  project
/boot/ 
  project
/build/target/ 
  project
/plugins/target/ 
  project
/plugins/lib_managed/ 
  project
/plugins/src_managed/

A .gitignore for an sbt project should contain these entries:

target/ 
lib_managed
/ 
src_managed
/ 
project
/boot/

Next Step

Read Basic Usage for basic sbt usage information.

Summary

  1. Create a launcher script.
  2. Setup your project information and directory structure by running sbt in your project directory.
  3. Put libraries in lib or configure automatic dependency management.
  4. Read RunningSbt for basic usage instructions.
  5. Start with BuildConfiguration for further project configuration

 

分享到:
评论

相关推荐

    scala-sbt-helloworld.zip

    sbt(Simple Build Tool)是Scala项目的默认构建工具,它允许用户以声明性的方式定义项目依赖和构建过程。在本教程中,我们将深入探讨如何使用VSCode(Visual Studio Code)创建一个名为"Scala-SBT-Helloworld"的...

    Scala-2.12.8 sbt-1.2.8 安装包

    sbt(Simple Build Tool)是Scala项目的默认构建工具,它基于Apache Ivy依赖管理系统,为Scala和Java项目提供了强大的构建功能。sbt 1.2.8是该工具的一个较旧但仍然广泛使用的版本,它支持构建配置、自动编译、测试...

    [SBT] SBT 入门教程 (Scala 实现) (英文版)

    Equip yourself with a high-productivity work environment using SBT, a build tool for Scala Overview Establish simple and complex projects quickly Employ Scala code to define the build Write build ...

    scala-intellij-bin-2017.2.13

    此外,插件还支持SBT(Simple Build Tool)构建系统,使得管理Scala项目的依赖和构建过程更为便捷。 对于Spark开发者来说,Scala插件更是一个不可或缺的工具。Apache Spark是一个分布式计算框架,其API主要使用...

    windows 10 系统Scala和sbt环境配置教程方法.docx

    SBT(Simple Build Tool)是 Scala 的构建工具,用于管理项目依赖关系和编译代码。要在 Windows 10 系统上安装 SBT,需要从官方网站下载 SBT 的安装包,网址为 ...

    sbt-1.3.8.tar.gz

    这个压缩包文件包含了sbt(Simple Build Tool)版本1.3.8的所有必要组件,允许开发者高效地构建、测试和管理他们的Scala或Java项目。 sbt是Scala社区广泛采用的构建工具,它的主要特点包括: 1. **自动化构建**:...

    scala-sbt_API

    SBT,全称为 Simple Build Tool,它以其灵活性和高效性在 Scala 开发者社区中广泛应用。在这个API文档中,开发者可以找到关于如何使用SBT进行项目构建、依赖管理、测试以及发布等关键信息。 版本0.13.12是2016年11...

    scala-SDK-4.2.0-vfinal-2.11-win32.win32.x86

    4. Scala 工具:包括 sbt(Simple Build Tool),这是 Scala 项目的主要构建工具,用于管理依赖、编译、打包和测试。 在提供的压缩包文件名称列表中,只提到了 "eclipse"。这可能意味着该 SDK 集成了 Eclipse IDE ...

    scala-2.13.0-M5.tgz

    8. **社区包管理**:Scala 2.13继续支持SBT(Simple Build Tool)作为主要的构建工具,同时也更加友好地支持Maven和Gradle等其他构建系统。 在解压“scala-2.13.0-M5.tgz”后,你会得到一系列文件和目录,包括Scala...

    scala-2.13.8 解压安装版

    6. **Sbt构建工具**:"scala"压缩包可能包含了Scala的构建工具SBT(Simple Build Tool),它是Scala项目的主要构建工具,可以管理依赖、编译、打包和测试。 7. **社区和文档**:Scala拥有活跃的开发者社区,提供了...

    scala-intellij-bin-2020.1.27.zip

    此外,该插件还支持Scala的构建工具SBT(Simple Build Tool),方便项目的构建和管理。 标签"scala idea"表明这个压缩包是为Scala开发者在IntelliJ IDEA中进行开发准备的。IntelliJ IDEA的用户界面友好,性能优秀,...

    sbt-launch-0.13.9

    **SBT(Scala Build Tool)** 是一个基于Java和Scala的高效、强大的构建工具,尤其在Scala开发领域中被广泛使用。它的全名是Simple Build Tool,正如其名,SBT旨在简化项目构建过程,提供了一种简洁的方式来管理依赖...

    sbt-launch

    `sbt-launch`是专门为Windows操作系统设计的Scala项目构建工具SBT(Simple Build Tool)的启动器。SBT是Scala社区广泛使用的自动化构建系统,它允许开发者高效地管理依赖、编译、打包、测试以及发布Scala和Java项目...

    sbt资源包,全平台版本sbt-platform

    Sbt(Simple Build Tool)是Scala项目的主要构建工具,它以其高效、灵活和强大的特性深受开发者喜爱。在 Scala 开发环境中,Sbt 起到了核心作用,它负责编译、测试、打包以及发布 Scala 应用程序。"sbt资源包,全...

    Simple Build Tool(sbt)0.13.8最新版.rar

    **Simple Build Tool (sbt)** 是一个强大的构建工具,主要用于Scala和Java项目。它采用声明式的方式来定义项目构建,使得开发者能够轻松管理依赖、编译、打包、测试以及发布项目。sbt以其高效和灵活的特性,深受...

    sbt-1.1.4 for windows.zip

    SBT(Simple Build Tool)是Scala编程语言生态系统中的核心构建工具,它为Scala开发者提供了一种高效、灵活的方式来管理项目依赖、编译源代码、运行测试以及打包应用程序。SBT的强大之处在于它能够自动化构建过程,...

    scala-2.11.0.zip

    8. **工具链**:Scala的构建工具sbt(Simple Build Tool)的相关代码也在源码包内,它使得Scala项目的构建和管理变得简单。 9. **兼容性**:Scala-2.11.x系列着重于与Java 7和8的兼容性,因此在源码中可以看到针对...

    Getting Started with SBT for Scala

    SBT是Scala的构建工具(Build Tool),其全称是Simple Build Tool,主要用于Scala和Java项目的构建和管理。通过SBT,开发者能够更高效地组织和执行项目的构建过程,包括编译代码、运行测试、打包应用等。 在描述中...

    scala-2.12.5.tgz

    在工具链方面,Scala 2.12.5与SBT(Simple Build Tool)紧密集成,这是Scala项目的主要构建工具。SBT提供了高效的依赖管理和构建流程,使得开发者能够快速构建、测试和打包Scala项目。 最后,值得注意的是,Scala ...

Global site tag (gtag.js) - Google Analytics