0301.Scala IDE for Eclipse

Scala IDE for Eclipse, http://www.scala-lang.org/node/94

在 Scala IDE 的模式下, 您不需要再手動安裝 Scala 編程語言包, 已整合在 Scala IDE 中, 是非常方便.

Scala IDE 特色

Scala IDE 的核心思維是無縫的(seamless)整合 Eclipse Java 工具集, 以提供許多特點給 Eclipse 使用者預計包括如下,
  • Support for mixed Scala/Java projects and any combination of Scala/Java project dependencies. Type driven operations are transparent across Scala and Java files and projects, allowing straightforward references from Scala to Java and vice versa.
  • A Scala editor with syntax highlighting, inferred type and scaladoc hovers, hyperlinking to definitions, code completion, error and warning markers, indentation, brace matching.
  • Project and source navigation including Scala support in the Package explorer view with embedded outline, outline view, quick outline, open type, open type hierarchy.
  • Incremental compilation, application launching with integrated debugger, hyperlinking from stacktraces to Scala  source, interactive console.
  • Support for Eclipse plugin and OSGi development including hyperlinking to Scala source from plugin.xml and manifest files.

The Scala IDE is released under a BSD-like license and community involvement in its development is strongly encouraged. See the developer documentation here.

YouTube Video

Code插入快顯功能(2.8 Dev)

YouTube Video


推薦(最低)版本在使用 Scala Eclipse 外掛的構成要件是,

安裝-以 JDK 1.7 / Eclipse 3.5 /3.6 為例

Scala IDE 的最佳安裝方式為持續的與 Eclipse 中的自動安裝與更新中心結繫.

您有二個方式(效果是相同的)在 Eclipse 中增加 Scala IDE 的官方下載中心資料, 首先從取得 Eclipse 3.5 / 3.6 並正確開啟後,
  1. 功能列 [Help] → [Install New Software ...] → [Available Software Site]" 接下來按 [Add...] 來開啟站台中心管理視窗 ...
  2. 功能列 [Windows] -> [Preferences] -> Install/Update -> Available Software Sites " 接下來按 [Add...]

更多相關 Eclipse 教學請見 老魚

增加 Scala 更新中心(範例)

我們進行 新增(Add) 的動作, 並填入下列資料, 再按 "OK" 鍵.
Name: Scala IDE Beta for Scala 2.8.1 final for Eclipse 3.5 and 3.6
Location: http://download.scala-ide.org/nightly-update-wip-exp-backport-2.8.1.final

Name: Scala IDE Beta for Scala 2.9.0 RC 1 final for Eclipse 3.6 only
Location: http://download.scala-ide.org/releases/wip_experiment-2.0.0-beta1

安裝 Scala IDE

功能列 [Help] → [Install New Software ...] → 選取 Work with: Scala IDE -> 安裝如下圖的選項.

If the Scala functionality appears to be non-functional after installing the Scala IDE and restarting Eclipse, in particular if Scala source files appear to be being interpreted as Java (with a consequently large number of "Java problem"s being reported against them, then please ensure that JDT Weaving is enabled by navigating "Preferences → JDT Weaving" then, if disabled, click the button to enable and follow the instructions to restart Eclipse. If this doesn't resolve your problem, check that JDT Weaving is still enabled after the restart. If not, please review the following section of this document ...
該版本基於一種與Eclipse JDT整合的新辦法,可以利用Equinox Aspects(Equinox項目是Eclipse開源組織提供的OSGi框架的實現)和與Andrew Eisenberg的AspectJ開發工具(AspectJ Development Tools,AJDT)聯合開發的 JDT weaving功能。 這樣可以在Eclipse Scala和Java工具之間實現更深入和更強大的互操作。由於長期存在的許多缺陷已得到解決,更多的JDT功能現在已經可以正確的應用在Scala項目中了。


測試範示 - HelloWorld.scala

在這是一個很短的指導如何在 Eclipse 建立一個 Scala - HelloWorld 應用程序, 前題是假設您已安裝有 Scala IDE 外掛,

  1. 首先您可以先手動切換 視景(perspective) 為 Scala perspective (非必要)
    1. (Window → Open Perspective → Other ... → Scala 再按 "OK")
  2. 上述的步驟原則上是可省略的, 在您建立 Scala 專案或是切換到 Scala 專案時, 視景原則上就會自動切換.
  • 建立一個新的 Scala 專案 "hello"
    首先按在功能列的 "File" -> "New → Scala Project(wizard)" 或 "Other..." 找. 在 "Project name" 欄位輸入 "hello"  並按確認 "Finish" 鈕.
  • 建立一個新的 Scala package(套件) 在原始碼文件夾 "src" 中
    在 "Package Explorer" 窗口的 "hello" 上 來展開這個專案的文件結構, 並且在其 "src" 文件夾上按右鍵開啟小窗口來 "New → Package" ; 在 "New Package" 窗口, 輸入 "hello" 在 "Name" 的欄位並且按 "Finish" 來完成動作.
  • 新增一個 Scala object "HelloWorld" 與 main 方法
    接下來在 "hello" 專案樹的 "hello" 套件上按右鍵; 選取 "New → Scala Object" 選項和輸入名稱 "HelloWorld" 在這 "Object name" 欄位. 按 "Finish" 鈕.
  • 撰寫程式碼列印一個訊息
    HelloWorld object extend Appplication 並且增加一個 println 方法的敘述句以便輸出指定的訊息在終端機.
  • 在 Scala 專案新增一個執行組態 (非必要動作)
    Select the menu item "Run → Run Configurations..." then double-click "Scala Application". Set the "Main class" to hello.HelloWorld and click the "Run" button.
如下圖的完整呈現: Scala IDE 2.8 + Eclipse 3.5 + JDK 1.7