Wednesday, October 31, 2012

An IDE for ScalaFX development? Yes - PLEEEEEASE!

This entry should tell you how to get an IDE (Integrated Development Environment) up and running for Scala development - and especially for ScalaFX (graphics application) development.

It shouldn't be even this difficult (and most likely will become easier over the years).

The *current* (Oct 2012) situation is that I fought over a week with Eclipse Juno without still getting it to fully work. With IntelliJ the fight was roughly half a day (not bad). 

With this text, you'll be up and running within an hour.

You shall need:
- OS X
- Scala 2.9.2 installed via HomeBrew.
- ScalaFX jar precompiled

You probably should read this earlier blog post first.



- Download "IntelliJ IDEA". Use the "Early Adapter Program" (recommended for Scala plugin to work) and take IDEA 12 (it has a great duck splash screen):

http://confluence.jetbrains.net/display/IDEADEV/IDEA+12+EAP   ( I took version 'idealC-122.639.dmg'. )

- Drag 'Leda-IC-122.639' app to somewhere (i.e. /Applications).

- Launch it and pick 'Open plugin manager' (top right corner of the welcome page):

- "Browser repositories…" > choose "Scala" plugin (v.0.6.287) (double click to download & install)
- You may also wish to install "SBT" plugin but it seems to only provide compilation help, not sure how it can be used for debugging.
- restart IntelliJ

THIS IS IMPORTANT!!!

In order to use the Scala plugin, it needs to be given a "language facet", essentially libraries that tell where Scala compiler & libraries can be found.

We'll do it here using the command-line-installed ("brew install scala") version 2.9.2 files.

- Create a project (i.e. from scratch)

Select type: "Java module"

Click "Scala" on the "desired technologies" page (below) and fill the "Create compiler library" and "Create standard library" names to your liking (and probably you want them to be 'global').

We'll make these point to the right HomeBrew-loaded jar's in a minute.





You should get to the main IDE soon.


There's a ton of things you should go through in File > Project Structure… Do it now.

Within there, you see 'Modules > Scala' that should be like this:


Notice that "scala-compiler" is selected as the way to compile Scala. This points to the scala-compiler.jar and scala-library.jar that we'll now define under "Global Libraries" (last entry of the "Project Structure…" dialog):

Make the entries look like this (in case you do have Scala 2.9.2 via 'brew'):




This should allow IDEA to compile Scala. 

NOTE: It is absolutely essential that you only play with one version of Scala. Don't download "another" 2.9.2 and make IDEA point to it (did not work - at least not for me).

- Within "Project Structure… > Libraries" add 'scalafx-1.0-SNAPSHOT.jar' (that you've snitched earlier, compiled with the same Scala version):


- To compile, "Build > Rebuild project" (I'm not a fan of automatic build)

- To start code, right click i.e. on 'Main.scala' and take 'run MainFX.main()' (no breakpoints etc.) or 'Debug 'MainFX.main()' (will stop at breakpoints).

Did it work?

Note that i.e. renaming the "Scala compiler library" seems to be enough to throw the "Scala facet" setting off the wall, and requires it to be reset ("Project Structure… > Facets)

References:

http://confluence.jetbrains.net/display/SCA/Getting+Started+with+IntelliJ+IDEA+Scala+Plugin


No comments: