【SBT构建scala项目】

一、环境准备

scala:http://www.scala-lang.org/

echo $SCALA_HOME

/Users/..../Documents/software/scala-2.11.7


sbt:http://www.scala-sbt.org/

$brew list sbt

/usr/local/Cellar/sbt/0.13.9/bin/sbt


sbt eclipse:https://github.com/typesafehub/sbteclipse


sbt assembly:https://github.com/sbt/sbt-assembly


二、sbt生成scala eclipse项目

2.1 添加sbt eclipse插件

$ ls
simple-sbt

$ pwd
/Users/.../Documents/workspace-scala2

$ tree .
.
└── simple-sbt
    ├── build.sbt
    └── project
        └── plugins.sbt

2 directories, 2 files

plugins.sbt文件内添加插件
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.4.0")

$cd simple-sbt
$sbt eclipse
[info] Loading project definition from /Users/.../Documents/workspace-scala2/simple-sbt/project
[info] Updating {file:/Users/.../Documents/workspace-scala2/simple-sbt/project/}simple-sbt-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to simple-sbt (in build file:/Users/.../Documents/workspace-scala2/simple-sbt/)
[info] About to create Eclipse project files for your project(s).
[info] Updating {file:/Users/.../Documents/workspace-scala2/simple-sbt/}simple-sbt...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Successfully created Eclipse project files for project(s):
[info] simple-sbt

$ ll
total 16
drwxr-xr-x  8 ...  staff  272 Dec 27 10:52 .
drwxr-xr-x  3 ...  staff  102 Dec 27 10:48 ..
-rw-r--r--  1 ...  staff  780 Dec 27 10:52 .classpath
-rw-r--r--  1 ...  staff  364 Dec 27 10:52 .project
-rw-r--r--  1 ...  staff    0 Dec 27 10:50 build.sbt
drwxr-xr-x  5 ...  staff  170 Dec 27 10:52 project
drwxr-xr-x  4 ...  staff  136 Dec 27 10:52 src
drwxr-xr-x  4 ...  staff  136 Dec 27 10:52 target
===> 生成了eclipse的 .classpath 和 .project目录

$tree -L 2
.
├── build.sbt
├── project
│   ├── plugins.sbt
│   ├── project
│   └── target
├── src
│   ├── main
│   └── test
└── target
    ├── resolution-cache
    └── streams

9 directories, 2 files
==> 发现没有resources目录
==> 在build.sbt里面添加
EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource

$sbt eclipse

$ tree -L 3
.
├── build.sbt
├── project
│   ├── plugins.sbt
│   ├── project
│   │   └── target
│   └── target
│       ├── config-classes
│       ├── resolution-cache
│       ├── scala-2.10
│       └── streams
├── src
│   ├── main
│   │   ├── java
│   │   ├── resources
│   │   ├── scala
│   │   └── scala-2.10
│   └── test
│       ├── java
│       ├── resources
│       ├── scala
│       └── scala-2.10
└── target
    ├── resolution-cache
    │   ├── default
    │   └── reports
    └── streams
        ├── $global
        ├── compile
        ├── runtime
        └── test

28 directories, 2 files
HEWEWU-M-F02V:simple-sbt w


导入到eclipse中。

2.2 

三、开发与部署

3.1 添加依赖

在build.sbt中添加依赖,可以再mvnrepository中查找依赖

name := "simple_sbt"

version := "1.0"

scalaVersion := "2.10.3"

EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource

libraryDependencies ++= Seq(  
    "org.json4s" %% "json4s-native" % "3.2.10",  
    "org.json4s" %% "json4s-jackson" % "3.2.10"
)

resolvers ++= Seq(  
    // HTTPS is unavailable for Maven Central  
    "Maven Repository"     at "http://repo.maven.apache.org/maven2",  
    "Apache Repository"    at "https://repository.apache.org/content/repositories/releases",  
    "JBoss Repository"     at "https://repository.jboss.org/nexus/content/repositories/releases/",  
    "MQTT Repository"	at "https://repo.eclipse.org/content/repositories/paho-releases/",  
    "Cloudera Repository"  at "http://repository.cloudera.com/artifactory/cloudera-repos/",  
    // For Sonatype publishing  
    // "sonatype-snapshots"   at "https://oss.sonatype.org/content/repositories/snapshots",  
    // "sonatype-staging"     at "https://oss.sonatype.org/service/local/staging/deploy/maven2/",  
    // also check the local Maven repository ~/.m2 
    Resolver.mavenLocal
)

执行sbt update会下载依赖
再执行sbt eclipse


转载于:https://my.oschina.net/u/204498/blog/551681

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值