Mathjax javascript librry setup

Scala Tools

Scala SDK and Eclipse

  • Its easist just to download the Scala SDK, which has Scala support already bundled into Eclipse. Note that the Scala SDK currently works best with Eclipse Indigo, especially the really cool Scala Worksheet
  • Mike Slinn’s Working With Scala IDE for Eclipse is free, and excellent.
  • Mikes Scala Notes has excellent material on setting up Eclipse and the Scala IDE

Eclipse and Scala IDE Set-up

  • Set your JAVA_HOME environment variable to the version of the Java SDK you are using. (Typically a version of Java 1.7)

  • To increase performance:
    • Use the 64-bit version of Eclipse and the Scala IDE if possible
    • Turn off ‘Mark occurrences’ (CMD-ALT-O on mac, Ctrl-Alt-O on PC). This is one of the actions that happen on every keystroke.
    • Turn off semantic highlighting
    • Eclipse Indigo is faster than Juno (The production release of the Scala IDE uses Indigo)
  • If you can increase your memory and resources for Eclipse. Mike recommends editing your eclipse.ini to the following
    • -Xmn128m
    • -Xss2m
    • -XX:+UseParallelGC
    • -XX:PermSize=256m
    • -XX:MaxPermSize=128m
    • -Xms1512m
    • -Xmx2124M
  • Follow Mike’s instructions for setting the Eclipse Preferences
    • Enable Always run in background and Show heap status.
    • General
      • Editors
      • Size of recently opened files list: increase from 4 to something more reasonable, like 15.
      • Structured Text Editors / Task Tags: enable Enable searching for Task Tags.
      • Text Editors:
        • Enable Insert spaces for tabs, Show print margin and Show line numbers. I set the print margin column to 150.
        • Spelling: click the browse button to specify a file for your spelling dictionary. Eclipse and Thunderbird can use the same file.
      • Keys - type in Scala in the search area and notice the Scala-related hotkeys that are predefined for you. You can change the definitions here.
      • Startup and Shutdown - Enable Refresh workspace on startup and disable Confirm exit when closing last window.
      • Web Browser - You can define your favorite browser here. For Mac, if you want to use Google Chrome, click the New… button and add the following:
        • Name: Chrome
        • Location: /usr/bin/open
        • Parameters: -a “/Applications/Google Chrome.app” %url%
        • On a Mac, also change the default Firefox entry to follow the same model used for Chrome ​* Workspace
        • Enable Refresh using native hooks or polling and Save automatically before build.
        • Text file encoding - Set to Other: UTF-8.
    • Install / Update / Automatic Updates - Enable Automatically find new updates and notify me. I also like to select Download new updates automatically and notify me when ready to install them.
    • Scala
      • Compiler - Enable deprecation and unchecked. I also like to add the following to Additional command line parameters: -Ywarn-adapted-args -Ywarn-value-discard -Xlint
      • You should explore the other Scala-related settings so you know what they are. I like the defaults just as they are.
    • Scala Worksheet - Maximum number of output characters to be shown after evaluation: 1000 characters is often not enough. Try 10000.
  • Normation - Optimizing Eclipse Performance is another good source of tuning Eclipse for Scala

Using the Scala Eclipse IDE

Simple Build Tool SBT

SBT Setup

  • Beef up the memory settings, and set the character encoding to UTF-8: -Xmx2048M ${SBT_OPTS} -XX:MaxPermSize=512m -Xss1M -Dfile.encoding=UTF8
  • You have 3 options to do this:
    1. Edit the SBT startup script directly sudo subl \which sbt` `
    2. Creste an $SBT_OPTS environment variable
    3. Create a file ~/.sbtconfig and then defi e the SBT_OPTS environment variable in it.
      • SBT_OPTS="-Xmx2048M -XX:MaxPermSize=512m -Xss1M -XX:+CMSClassUnloadingEnabled -Dfile.encoding=UTF8 $SBT_OPTS"
      • Adding $SBT_OPTS at the end allows you to pass in addition options or overide them by setting using export SBT_OPTS=" ..."

Standard Directory Structure

  • The standard directory structure for a Scala project is the same as for a Java Maven project:
  • SBT and Eclipse use the standard Maven directory structure:

    project-root .build.sbt - SBT build file .gitignore - files for git to ignore scalastyle_config.xml - ScalaStyle config file

    lib                              - Jar file dependencies (SBT unmanaged dependencies) go here
    src
        main
            java
            scala
                ca
                    bashd
                        my-package
            resources
        test
            java
            scala
                ca
                    bashd
                        my-package

SBT Common Commands

  • help <command> Displays detailed help for the specified command. If no command is provided, displays brief descriptions of all commands.
  • reload Reloads the build definition (build.sbt, project/.scala, project/.sbt files). Needed if you change the build definition.
  • exit Exits the interactive SBT command primpt *clean Deletes all generated files (in the target directory).
  • compile Compiles the main sources (in src/main/scala and src/main/java directories).
  • test Compiles and runs all tests.
  • console Starts the Scala interpreter with a classpath including the compiled sources and all dependencies. To return to sbt, type :quit, Ctrl+D (Unix), or Ctrl+Z (Windows).
  • run <argument>* Runs the main class for the project in the same virtual machine as sbt.
  • package Creates a jar file containing the files in src/main/resources and the classes compiled from src/main/scala and src/main/java.
  • doc Generates API documentation for Scala source files in src/main/scala using scaladoc. test:doc generates API documentation for source files in src/test/scala.
  • eclipse creates Eclipse project files from the SBT configuration (sbteclipse plug-in)

My SBT Plug-Ins

ScalaDoc

ScalaDoc is Scala’s version of JavaDoc … it uses a structured set of comments to document Scala code.

ScalaStyle

Other Scala Tools

  • Tools and Libraries page on wiki.scala-long.org has a comprehensive list
  • implicit.ly Notes - Notes page for implicit.ly, a Scala libraries cataloging site
  • Giter8 - Giter8 is a command line tool to generate files and directories from templates published on any git repository. It’s implemented in Scala and runs through the Simple Build Tool launcher, but it can produce output for any purpose.
    • scala-sbt g8 template - A Giter8 template that creates a sbt project with support for Scala 2.10 and ScalaTest. Based on sbt 0.12
  • Gatling Tool- A stress testing tool, a la JMeter, written in Scala
  • Scalariform - Source code formatter for Scala. Its integrated into Eclipse as part of the Scala IDE. There is a SublimeText Plug-In Sublime-Scalariform

Code Coverage for Scala

Command Line Paersing in Scala

Comments