10 Steps to Happiness with Scala and NetBeans IDE

Took me about 20 minutes to figure out the procedure below, including downloading the related software. At the end, you'll have the samples from the Scala distribution up and running in NetBeans IDE. Click to enlarge the image below:



Let's get started.

  1. Get NetBeans IDE. Download NetBeans IDE 7.3.1, which is the latest official release of NetBeans IDE at the time of writing. If all you want to do is use Scala in NetBeans IDE, make sure to download the "Java SE" distribution, since that's the smallest distribution providing the basic toolset on top of which you will install the Scala plugin.

  2. Get Scala. Download Scala and set it up so that when you run Scala on the command line, it works. That's a nice way to check that you have downloaded and installed Scala correctly.

  3. Connect Scala to NetBeans IDE. Open the "etc/netbeans.conf" file, in the installation directory of NetBeans IDE, and use "-J-Dscala.home" in "netbeans_default_options" to point to your Scala installation. For example, on Ubuntu, my "netbeans_default_options" in "etc/netbeans.conf" is now as follows:
    netbeans_default_options="--laf Nimbus -J-Dscala.home=/home/geertjan/scala/scala-2.10.2 
    -J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true 
    -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true 
    -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true"
  4. Install the NetBeans Scala Plugin. Start NetBeans IDE and go to Tools | Plugins and install all the Scala modules which, together, constitute the NetBeans Scala plugin:



  5. Verify Scala is Connected to NetBeans IDE. After installing all the modules shown above, go to Tools | Scala Platforms. Each of the tabs, "Classes", "Sources", and "Javadoc" should show some content, based on a combination of the Java platform and the Scala platform.



  6. Take a Look at the Project Templates. Go to the New Project wizard (Ctrl-Shift-N) and notice there are three new project templates in a new category appropriately named Scala:



  7. Import the Scala Samples into NetBeans IDE. Select "Scala Project with Existing Sources" and click Next. Name the new project "scala-samples" and place it anywhere you like on disk, e.g., in the NetBeans Projects folder:



    Click Next. Browse to the root folder of your Scala download, i.e., in my case, "/home/geertjan/scala/scala-2.10.2".



    Then click Next again. In the "Excludes" field, exclude all the folders that are not named "examples". That is, we're creating a new NetBeans project based on the "examples" folder in the Scala distribution, hence we don't want all the non-examples folders in our project.



    Click Finish and now you have a NetBeans Scala project consisting of all the samples in the Scala distribution:



  8. Fix Import Statements. Right-click and build the project and notice that there are some Scala packages that are incorrectly declared. I.e., the Duration class is in a different package than that which is declared in some of the examples, so use the error annotations and hints to correct those occurrences.



  9. Define Run Configurations. I noticed that individual files can't be run, i.e., no right-click and Run File. So go to the toolbar and create some run configurations:



    In each case, simply type the full path to the class you want to run:



  10. Run the Project. Finally, when you run the project, and you have a main class defined as shown in the previous step, you'll see the result in the Output window:


Seems to me that the NetBeans Scala plugin is very mature. Syntax coloring, code completion, etc. Nice.

Comments:

This is a windows 8 issue. When I add "-J-Dscala.home=C:\Program Files (x86)\scala" to the 'netbeans_default_options' in the netbeans.conf file NetBeans fails to load.

I am able to get a version number from the command prompt, so I know scala is installed.

Do you have any experience with scala on windows?
Thanks!

Posted by William Bradley Rouse on August 23, 2013 at 08:38 PM PDT #

-J-Dscala.home=C:\PROGRA~1\scala

Posted by Geertjan on August 24, 2013 at 09:29 AM PDT #

The scala plugin does not seem so happy with Netbeans 7.4. Do you know any plans to make it compatible?

Posted by guest on October 20, 2013 at 09:14 PM PDT #

Yes Scala does not work with 7.4 :-(

Posted by guest on October 30, 2013 at 06:42 AM PDT #

7.4 was released when? Last week? So, give it some time, OK. Let the Scala developers work on updating the plugin. Give them some time.

Posted by Geertjan on October 30, 2013 at 06:59 AM PDT #

Haven't tried it yet, but: http://sourceforge.net/projects/erlybird/files/nb-scala/7.x_2.10.x/nbscala-7.4_2.10.x-1.6.1.1.zip/download

Posted by guest on November 09, 2013 at 02:21 PM PST #

If you're having problems at step 5 on windows simply add the environment variable SCALA_HOME (obviously pointing to the scala home directory) through advanced settings. that got me going.

Posted by guest on November 22, 2013 at 08:31 AM PST #

Thank you for making this easy-to-learn tutorial.
I'm a Java programmer trying to learn Scala.

So, I set up Netbeans + Scala in Windows 7.
I went past step #5 and tried to create a Scala Application project.
Netbeans then created a package with a default class. Inside the class was a method like so:

def main(args: Array[String]): Unit = {
println("Hello, world!")
}

However when I tried to run the file (Shift+F6), the IDE complained:
Class "testscala.Main" does not have a main method.

The project itself though, did run (F6) well.

I wonder what I did miss there...

Thanks again,

Posted by akkumaru on December 16, 2013 at 01:41 AM PST #

Thanks for sharing

Posted by Azuryy on December 25, 2013 at 08:20 PM PST #

What is the procedure of installing scala (downloaded from the site) w/NB 8?

Posted by Aparna Basu on March 09, 2014 at 09:48 AM PDT #

I wanted to add that I would like to know howto for wintel and mac (pl. refer to my earlier post)

Posted by Aparna Basu on March 09, 2014 at 09:50 AM PDT #

Thank you, Geertjan, very useful post. Worked like a charm for me.

Posted by Mark Kerzner on March 12, 2014 at 11:31 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today