Friday, March 11, 2011

Scala with SBT and Eclipsify

So, I'm new to Scala but wanted to start playing with it. The language, concepts and future of this language are very exciting. One thing I am noticing is that the plugins are very imature. Please note here that I am not criticising anyone working on the plugins. I am simply noting that they haven't been around for a thousand years and put through their paces like their Java counterparts.

I've recently fought to get a simple project created using sbt and imported in to eclipse using sbt eclipsify. Unfortunately, being so new to these tools, I struggled a bit. Below is a summary of how I achieved it.

  1. Download SBT and get it running... this is pretty simple and the directions located here explain it very well.  
  2. Now that you have SBT downloaded and setup, it is runnable from the command line in any directory.  Navigate to where your eclipse projects are normally kept, in my case
  3. D:\>cd D:\development\workspace
    D:\development\workspace>mkdir Concepts
    D:\development\workspace>cd Concepts
    D:\development\workspace\Concepts>sbt
    D:\development\workspace\Concepts>set SCRIPT_DIR=D:\cory\sbt\
    D:\development\workspace\Concepts>java -Xmx512M -jar "D:\cory\sbt\sbt-launch-0.7.4.jar"
    Project does not exist, create new project? (y/N/s) y
    Name: Concepts
    Organization: Maksymchuk
    Version [1.0]:
    Scala version [2.7.7]:
    sbt version [0.7.4]:
    Getting Scala 2.7.7 ...
    :: retrieving :: org.scala-tools.sbt#boot-scala
    confs: [default]
    2 artifacts copied, 0 already retrieved (9911kB/593ms)
    Getting org.scala-tools.sbt sbt_2.7.7 0.7.4 ...
    :: retrieving :: org.scala-tools.sbt#boot-app
    confs: [default]
    15 artifacts copied, 0 already retrieved (4096kB/719ms)
    [success] Successfully initialized directory structure.
    [info] Building project Concepts 1.0 against Scala 2.7.7
    [info] using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
    >
    
  4. So now you have it, a project created using SBT sitting on your file system. Well done. Now the tricky part, using Eclipsify to get it into Eclipse.
  5. I downloaded Eclipsify from here, then extracted the zip on to my filesystem.  In the unzipped file system, I navigated to "musk-SbtEclipsify-ca279bd/dist" and coppied the file "sbteclipsify-0.4.0.jar" from there to a new folder I created in "Concepts\project\plugins" where concepts is the directory created above.
  6. Now create a Scala file in the concepts directory called "Plugins.scala" as follows
  7. import sbt._ 
    class Plugins(info: ProjectInfo) extends PluginDefinition(info) {   
     val a = "de.element34" % "sbt-eclipsify" % "0.7.0"  
    }
    
  8. Next, create a file called Concepts.scala in Concepts\project\build
  9. import sbt._
    import de.element34.sbteclipsify._
    class Concepts(info: ProjectInfo) extends DefaultProject(info) with Eclipsify {
      // the project definition here
    }
    
  10. Now in your command line window (running sbt) run this command
  11. > reload
    
  12. This should have created an eclipse command that can be used in the SBT console
  13. > eclipse
    
  14. Now go to Eclipse and import your project! The files you need have been generated.

No comments:

Post a Comment