Friday, April 27, 2012

Scala IDE for Eclipse

Getting Started 

Requirements

Installation

The Scala IDE for Eclipse is best installed (and updated) directly from within Eclipse.
First follow the navigation path "Help → Software Updates ... → Available Software" then click the "Add Site..." button.

Choosing what version to install

All update sites for installation are at http://download.scala-ide.org/. The constellation of versions can be daunting at first. Read this paragraph to make an informed choice.
The Eclipse plugin comes with a Scala compiler and Scala library. In a given Eclipse installation there can be a single version of the Scala plugin for Eclipse, so you need to decide what Scala version you are going to use. In other words, the choice of Scala version (2.8.x, 2.9.x, etc) is not per project, but per Eclipse installation.
Scala IDE for Eclipse supports three versions of the Scala compiler:
  • 2.9.x supports projects using Scala 2.9.1 or 2.9.0-1. This is the currently release version of Scala, so you should choose this if you are unsure.
  • 2.8.x is a backwards compatible version for projects using Scala 2.8.1 or 2.8.2.
  • 2.10 is a build relative to Scala trunk. Choose this if you want the bleeding edge, or working on scalac itself
Once you decided for the Scala version, you need to choose a version of the IDE.
  • 2.0 is a stable branch for the upcoming 2.0 release. We release nightlies and betas. Choose the latest beta for 2.9 if you are unsure what to install.
  • 2.1 is the upcoming 2.1 release. It will be less stable and contain more features.
Check http://download.scala-ide.org/ for all downloads.

Tutorial

Here's a short tutorial how to create a "Hello World" application with Eclipse. It assumes that you have installed the plugin as described above and switched to the Scala perspective (Window → Open Perspective → Other → Scala then click"OK").
  1. Create a new Scala project "hello"
    • First click the "New → Scala Project" item in the "File" menu. 
    • Enter "hello" in the "Project name" field.
    • Click the "Finish" button.
  2. Create a new Scala package in source folder "src"
    • Right-click on the "hello" project in the "Package Explorer" tab of the projects pane.
    • Select the "New → Package" menu item.
    • in the "New Package" window, enter "hello" in the "Name" field.
    • Press the "Finish" button.
  3. Create a Scala object HelloWorld with a main method
    • First expand the "hello" project tree and right-click on the "hello" package
    • Select the "New → Scala Object" menu item and enter HelloWorld in the "Object name" field. 
    • Press the "Finish" button.
  4. Extend the code to print a message
    • Make the HelloWorld object implement the main method and add a println statement (see image, below).
  5. Create a Run configuration for the Scala project
    • Right click on HelloWorld.scala in the Package Explorer,
    • Select "Run as ..." and select "Scala Application"
    • Select the first matching item, the "HelloWorld" class.
    • Click the "Ok" button.
Hello World code screenshot


 


Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 comments: on "Scala IDE for Eclipse"

Post a Comment