Scala Plugin for Eclipse

The Scala plugin for Eclipse is centered around seamless integration with the Eclipse Java tools, providing many of the features Eclipse users have come to expect including,

  • 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 plugin is released under a BSD-like license and community involvement in its development is strongly encouraged. See the developer documentation here.

Requirements

The recommended (and minimum) versions of the components required to use the Scala Eclipse plugin are,

Installation

The Scala Plugin 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 to get to the following dialog,

Adding the Scala update siteAdding the Scala update site

 

Enter this URL in the "Location" field and click the "OK" button:

http://www.scala-lang.org/scala-eclipse-plugin

You should then see "Scala Eclipse Plugin" offered for installation. Click on the "Install ..." button and follow the instructions from there.

If you would rather do an offline installation there is an archive of the 2.7.2 release along with its MD5 sum.
 
Important Upgrade Note

If you have projects created using earlier versions of this plugin, including recent pre-release versions, then you might need to modify them before they will build correctly.

All newly created projects will be correctly configured, so if this is your first use of the Scala Eclipse plugin, please skip to the next section.

For each older project please check the following,

  • The .project should be of the following form,

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>Project name</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>ch.epfl.lamp.sdt.core.scalabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>ch.epfl.lamp.sdt.core.scalanature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

Note that there should not be a buildCommand entry for the Eclipse Java builder.
  • The .classpath should be of the following form,

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src" />
    <classpathentry kind="con" path="ch.epfl.lamp.sdt.launching.SCALA_CONTAINER" />
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" />
    <classpathentry kind="output" path="bin" />
</classpath>

Note the SCALA_CONTAINER entry and that it preceeds the JRE_CONTAINER entry.
  • The per-project properties should be set as follows,
Right click on the project in the Package explorer, select "Properties Java Compiler Building". Enusre that "Enable project specific settings" is checked, then uncheck "Scrub output folders when cleaning projects" and add "*.scala" to the "Filtered resources" field.
 

 

Test Example

Here's a short tutorial how to create a HelloWorld 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").

  • Create a new Scala project "hello"
    First click the "New → Scala Project" item in the "File" menu. Enter "hello" in the "Project name" field and click the "Finish" button.
  • Create a new Scala package in source folder "src"
    Right-click on the "hello" project in the "Package Explorer" tab of the projects pane and select the "New → Package" menu item; in the "New Package" window, enter "hello" in the "Name" field and press the "Finish" button.
  • Create a Scala object "HelloWorld" with main method
    First expand the "hello" project tree and right-click on the "hello" package; then select the "New → Scala Object" menu item and enter "HelloWorld" in the "Object name" field. Press the "Finish" button.
  • Extend the code to print a message
    Make the HelloWorld object extend Appplication and add a println statement to the console.
  • Create a Run configuration for the Scala Project
    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 "Hello world!" in EclipseScala "Hello world!" in Eclipse

 

Feedback

You have several ways to provide your feedback on the Scala plugin:

 

 

 

Copyright © 2008 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland