一、环境准备
scala:http://www.scala-lang.org/
echo $SCALA_HOME
/Users/..../Documents/software/scala-2.11.7
$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