The "Getting started" section of the "Functional Programming with Scala" course mentions using Eclipse to build the first 'hello world' kind of project, but if you'd rather not get out of your Emacs comfort zone, there is a different way to do the same (credits to numerous online sources).
sbt
(sudo apt-get install sbt
) and scala
(download from here)ensime
plugin for sbt
: Create a directory ~/.sbt/0.13/plugins
, and create plugins.sbt
resolvers += "Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases"
addSbtPlugin("org.ensime" % "ensime-sbt-cmd" % "0.1.2")
scala-mode2
Emacs: if you have Emacs24, this is as straightforward as running M-x package-list-packages
and finding it)ensime
: Download the latest .tar.gz
, and install it somewhere under .emacs.d
, then modify your .emacs
to load the appropriate paths:
(add-to-list 'load-path "~/.emacs.d/ensime/elisp")
(require 'ensime)
(add-hook 'scala-mode-hook 'ensime-scala-mode-hook)
mkdir helloworld; cd helloworld
build.sbt
with the following
name := "hello_world"
version := "1.0"
ensime
: sbt ensime generate
Main.scala
ensime
in Emacs: M-x ensime
(say 'yes' to various prompts). You should see something like "ENSIME ready. May the _ be with you." in the minibuffer.
package greeter
object Hello extends App {
println("Hello World")
}
C-c C-b v
, this brings up an sbt
console inside Emacs (similar to how Slime works with Lisp)run
in the console, you should see something like
> run
[info] Compiling 1 Scala source to /home/agam/Scala/hello-world/target/scala-2.10/classes...
[info] Running greeter.Hello
Hello World
[success] Total time: 2 s, completed Jul 30, 2014 5:03:35 PM
... and that's it!