X

Geertjan's Blog

  • August 17, 2013

10 Steps to Happiness with Scala and NetBeans IDE

Geertjan Wielenga
Product Manager

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.

Join the discussion

Comments ( 19 )
  • William Bradley Rouse Saturday, August 24, 2013

    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!


  • Geertjan Saturday, August 24, 2013

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


  • guest Monday, October 21, 2013

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


  • guest Wednesday, October 30, 2013

    Yes Scala does not work with 7.4 :-(


  • Geertjan Wednesday, October 30, 2013

    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.


  • guest Saturday, November 9, 2013
  • guest Friday, November 22, 2013

    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.


  • akkumaru Monday, December 16, 2013

    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,


  • Azuryy Thursday, December 26, 2013

    Thanks for sharing


  • Aparna Basu Sunday, March 9, 2014

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


  • Aparna Basu Sunday, March 9, 2014

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


  • Mark Kerzner Wednesday, March 12, 2014

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


  • guest Friday, February 13, 2015

    Have anyone done this with Netbeans 8.0+ ? I can point Netbeans to the installation folder just fine, but when I try to start a new project, the only template I see is the ScalaSbtProject. I have previously used this plugin on a different computer, and then there were at least a Scala Application template if I remember correctly.


  • Baba the Dw@rf Saturday, February 21, 2015

    Thank you, it alsmost works.

    My last problem is that there is no way on creating or opening a scala project. I'm on Netbeans 8.0, have installed scala plugins for project support and linked Netbeans with the latest scala platform, but I still can't create a project.


  • guest Friday, March 27, 2015

    I have tried every which way to install and run scala on NB 8.0.2 on windows 7

    jdk 8 upd 31

    I have set my SCALA_HOME to a 2.10.5 distribution as well as in the conf file.

    The platform shows this 2.10.5 distribution

    Downloaded the plugins, new project errors off with a file not found "sh"

    But, the library dependency shows 2.11.4 ?

    Does the scala plugin work with 2.11 ?

    Have reinstalled several times with various combinations --

    Any thoughts would be appreciated.


  • guest Friday, November 6, 2015

    If adding -J-Dscala.home=C:\Program Files (x86)\scala to your netbeans.conf file does not work, add " " around the path, i.e. "C:\Program Files (x86)\scala", as spaces cannot be read.


  • guest Thursday, December 24, 2015

    Hi,

    I got stuck at step#5. In Scala Platform Manager, I can see correct information under CLASSES and JAVADOC tabs, but nothing is getting displayed under SOURCES tab. So when I try to create new project, I can't get options to create SCALA APPLICATION, SCALA CLASS LIB, SCALA PROJECT WITH EXISTING RESOURCES.

    Please help.


  • guest Friday, August 26, 2016

    Tutorial invalid for Year 2016 . NetBeans with SBT plugin.

    Possible to put latest tutorial? Struggling to make scala run NetBeans.


  • guest Friday, February 24, 2017

    I had the same problem as the post above - could not manage to get Scala run on NetBeans. The plugins install fine, but altering the netbeans.conf file caused the program to fail on startup. I tried several approaches to this but could not get the path to work.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.