Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build Scala applications in Sublime Text 3?

I'd like to be able to build Scala applications in Sublime Text 3 on Mac 10.9.3. I have Scala 2.11.1 and sbt 0.13.5 installed and they all work fine. I installed them by homebrew.

However, I can't seem to find how to create a build system for Scala projects. For example, this one doesn't work:

{
    "cmd": ["sbt", "test"],
    "selector": "source.scala",
    "working_dir": "${project_path}"
}

I found a couple of different ones as well but they didn't work for me, either. Your thoughts?

UPDATE:

[Errno 2] No such file or directory: 'sbt'
[cmd: ['sbt', 'test']]
[dir: /Users/alex/Documents/projects/scala/dir1]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
[Finished]

UPDATE2:

{
    "cmd": ["/usr/local/bin/sbt", "test"],
    "selector": "source.scala",
    "working_dir": "${project_path}"
}

An app:

class MainTest extends App {
  println("Hellowa!")     
}

The output:

 [0m[[0minfo[0m] [0mSet current project to scala (in build file:/Users/alex/Documents/projects/scala/)[0m
[0m[[0minfo[0m] [0mCompiling 1 Scala source to /Users/alex/Documents/projects/scala/target/scala-2.10/classes...[0m
[0m[[32msuccess[0m] [0mTotal time: 4 s, completed Jun 16, 2014 4:51:38 PM[0m
[Finished in 7.2s]
like image 956
Incerteza Avatar asked Jun 15 '14 13:06

Incerteza


People also ask

How do I compile a Scala program?

To compile the code, type "scalac hello_world. scala" and press enter. You can see two class files HelloWorld$. class, HelloWorld.

How do I create a Build System in Sublime Text?

Sublime Text is able to run build programs such as 'make', either when a key in pressed (F7 by default), or when a file is saved. The build system to use can be select from the Tools/Build System menu. If a project is open, the selected build system will be remembered for the project.

How do I compile in Sublime Text 3?

Then you can compile the current Java source file by clicking Tools > Build or press the shortcut key Ctrl + B. The . class file is generated in the same folder as the source file.


1 Answers

Homebrew installs executables in /usr/local/bin, but the error text you have now provided shows that that directory isn't in your path.

Two ways you could fix it:

1) Change "cmd": ["sbt", "test"], to "cmd": ["/usr/local/bin/sbt", "test"],

2) Add /usr/local/bin to your PATH environment variable. Note that you'll need to do this in such a way that GUI apps like Sublime Text notice the change; see e.g. Setting environment variables in OS X? for details

like image 191
Seth Tisue Avatar answered Sep 28 '22 01:09

Seth Tisue