2014年8月27日 星期三

[筆記] 如何安裝使用Stbeclipse



[碎念] 有時候真覺得自己有點死腦筋,明明官方的教學範例用的是不熟悉的sbt,那就選其他的學習方法就好了,但是就覺得不搞懂就全身不舒服....

故事是這樣,想玩玩看 Akka 和 Play ,結果這兩個都是Scala based 的Framework,縱使他們都有提供Java的Sloution,但是範例程式通通都適用sbt在build,所以只好也來玩一下sbt。


=====以下是正題===========以下是正題===========以下是正題======


SbtEclipse 不像一般plugin (如m2e)透過Eclipse內部安裝,所以步驟有些奇怪,參考官方文件


步驟一:安裝SBT


因為使用mac很簡單,只要執行
brew install sbt


安裝好以後,可以在home目錄下看到.sbt 的目錄(如果需要額外設定可以touch ~/.sbtconfig)
在~/.sbt/0.13/plugins/ 下create一個檔案plugins.sbt,並且填入以下內容:

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")


步驟二:下載專案並且產生Eclipse 專案格式


在這邊我下載官方akka 的 source code,其中有個子專是akka-sample

git clone https://github.com/akka/akka.git


進入專案目錄,輸入sbt進入sbt的console,如果第一次執行sbt,他會進行一些初始化的動作


# sbt
[info] Loading global plugins from /Users/howie/.sbt/0.13/plugins
[info] Updating {file:/Users/howie/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] downloading http://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbteclipse/sbteclipse-plugin/scala_2.10/sbt_0.13/2.5.0/jars/sbteclipse-plugin.jar ...
[info]  [SUCCESSFUL ] com.typesafe.sbteclipse#sbteclipse-plugin;2.5.0!sbteclipse-plugin.jar (1585ms)
[info] downloading http://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbteclipse/sbteclipse-core/scala_2.10/sbt_0.13/2.5.0/jars/sbteclipse-core.jar ...
[info]  [SUCCESSFUL ] com.typesafe.sbteclipse#sbteclipse-core;2.5.0!sbteclipse-core.jar (3590ms)
[info] Done updating.
[info] Set current project to howie (in build file:/Users/howie/)
>

不果如果你是在akka的目錄下執行sbt,他就會直接開始執行專案初始化,如下

# sbt
[info] Loading global plugins from /Users/howie/.sbt/0.13/plugins
[info] Loading project definition from /Users/howie/workspace/git_repository/example/akka/project
[info] Updating {file:/Users/howie/workspace/git_repository/example/akka/project/}akka-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 14 Scala sources to /Users/howie/workspace/git_repository/example/akka/project/target/scala-2.10/sbt-0.13/classes...
[warn] there were 24 deprecation warning(s); re-run with -deprecation for details
[warn] there were 7 feature warning(s); re-run with -feature for details
[warn] two warnings found
[info] Set current project to akka (in build file:/Users/howie/workspace/git_repository/example/akka/)
akka >

然後輸入eclipse 後,才會把專案正是轉成eclipse可讀的專案格式
akka > eclipse
[info] About to create Eclipse project files for your project(s).
[info] Updating {file:/Users/howie/workspace/git_repository/example/akka/}akka-actor...
[info] Done updating.
[info] Updating {file:/Users/howie/workspace/git_repository/example/akka/}akka-testkit...
[info] Done updating.
.
.
.
[info] Updating {file:/Users/howie/workspace/git_repository/example/akka/}akka-sample-remote-java...
[info] Done updating.
[info] Successfully created Eclipse project files for project(s):
[info] akka-actor-tests
[info] akka-sample-osgi-dining-hakkers-api
[info] akka-sample-fsm-scala
[info] akka-camel
[info] akka-multi-node-testkit
[info] akka-sample-camel-scala
[info] akka-sample-osgi-dining-hakkers-uncommons
[info] akka-sample-cluster-java
[info] akka-docs
[info] akka-sample-remote-scala
[info] akka-sample-osgi-dining-hakkers-integration
[info] akka-agent
[info] akka-sample-osgi-dining-hakkers-test
[info] akka-actor
[info] akka-sample-persistence-scala
[info] akka-slf4j
[info] akka-remote
[info] akka-cluster
[info] akka-sample-osgi-dining-hakkers-command
[info] akka-sample-cluster-scala
[info] akka-persistence-experimental-tck
[info] akka-persistence-experimental
[info] akka-sample-hello-kernel
[info] akka-sample-persistence-java
[info] akka-testkit
[info] akka-sample-osgi-dining-hakkers-core
[info] akka-sample-main-java
[info] akka-zeromq
[info] akka-sample-main-scala
[info] akka-sample-multi-node-scala
[info] akka-remote-tests
[info] akka-kernel
[info] akka-sample-camel-java
[info] akka-contrib
[info] akka-osgi
[info] akka-sample-remote-java
akka >

好接下來終於可以好好研究akka要怎麼玩了...:P

沒有留言 :