18.7. Using SBT with Eclipse
Problem
You want to use Eclipse with a project you’re managing with SBT.
Solution
Use the Scala IDE for Eclipse project so you can work on Scala projects in Eclipse, and use the sbteclipse plug-in to enable SBT to generate files for Eclipse.
The Scala IDE for Eclipse project lets you edit Scala code in Eclipse. With syntax highlighting, code completion, debugging, and many other features, it makes Scala development in Eclipse a pleasure.
To use the sbteclipse plug-in, download it per the instructions on
the website. Once installed, when you’re in the root directory of an SBT
project, type sbt eclipse
to generate
the files Eclipse needs. You may see a lot of output the first time you
run the command as SBT checks everything it needs, but at the end of the
output you should see a “success” message, like this:
$ sbt eclipse
[info] Successfully created Eclipse project files for project(s):
[info] YourProjectNameHere
The plug-in generates the two files Eclipse needs, the .classpath and .project files.
Once these files are generated, go to Eclipse and follow the usual steps to import a project into the Eclipse workspace: File → Import → Existing Projects into Workspace. Your project will then appear in the Eclipse Navigator, Project Explorer, Package Explorer, and other views.
Discussion
The .classpath file is an XML
file that contains a number of <classpathentry>
tags, like
this:
<classpath>
<classpathentry
output=
"target/scala-2.10/classes"
path=
"src/main/scala"
Get Scala Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.