1、環境準備java
scala:http://www.scala-lang.org/ git
echo $SCALA_HOMEgithub
/Users/..../Documents/software/scala-2.11.7apache
sbt:http://www.scala-sbt.org/json
$brew list sbteclipse
/usr/local/Cellar/sbt/0.13.9/bin/sbtmaven
sbt eclipse:https://github.com/typesafehub/sbteclipseui
sbt assembly:https://github.com/sbt/sbt-assemblyspa
2、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、開發與部署
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