2 Dec 2010

Running SBT (or any shell command) from Eclipse

(download)
Mostly when I'm writing code I'm in the Scala IDE for Eclipse, with a separate terminal window containing SBT running ~test-quick or jetty-run. But flipping back and forth between terminal and Eclipse is non-optimal, so I went digging for Eclipse + SBT integrations.

There are a few mentioned on the SBT site, but I realized all I needed was a shell prompt as a view in Eclipse and I'd be happy.  And of course it exists already as "Target Management Terminal", part of the Galileo update site.

  1. Eclipse > Install New Software....
  2. From "Work with:" select Galileo (or whatever's appropriate for your version of Eclipse).
  3. Type "terminal" in the search box, and select Target Management Terminal.
  4. Go through the download, restart process.
  5. Eclipse > Preferences and search for Terminal if you want to invert the colours (I did).
  6. Window > Show View > Other and select Terminal to show the Terminal view in Eclipse.
  7. Click the green connect button and set up the type of terminal you want (ssh to localhost in my case, and I'm prompted for a password).
  8. Login, you have a shell, do what you want, such as cd into your project and run SBT.

Probably totally obvious, but I missed this trick of having access to a shell from Eclipse.

23 Jul 2009

Using an existing Scala + Maven project in Eclipse

In case you're having problems using the Scala IDE for Eclipse with Maven projects, here's what I do:
  • Generate the Eclipse project files from the shell: mvn eclipse:eclipse. If you already have Eclipse .project files, you'll have to remove them first or mvn eclipse:clean.
  • In Eclipse, do a File -> Import... and select "General -> Existing Projects into Workspace", navigate to my maven project and select it.
  • This gives you a Scala project, but you'll need to enable Maven: right click on the root of the project in the Package Explorer in Eclipse, select Maven menu and enable.

The plugins I have look like this:
Media_httpfarm4static_rflee

...and it all works very well. The Maven plugin is the m2 one.

Troubleshooting: If that doesn't work first time for you: Project -> Clean... is your friend. If you're still having problems, a Refresh and Close Project followed by an Open project is good. In the worst case, close the project, exit Eclipse, remove the .metadata folder (at your own risk), and restart.

You might also want to check out the Scala IDE for Eclipse wiki pages for how others use Maven.

And for the record, I'm using a Mac (64bit, 10.5.7), with Maven 2.2.0 configured in Eclipse preferences to be an External installation (not the Embedded, but I don't know if that makes a difference or not), JDK 1.5, using Eclipse classic 3.4.2.

Richard Dallaway's Posterous

Director at Spiral Arm Ltd. We build stuff using Scala+Lift, offer consulting & create new projects. I live in Brighton, UK.