david hol
david hol

Reputation: 1280

How to run scala code from terminal

I have a simple Scala code that i want to run from osx Terminal.
Currently, my code runs in intellij.

object test
{
  def main(args: Array[String]): Unit =
  {
     // my code
  }
}

So i have this .scala path:

/Users/rdave/projects/test.scala

This is what i have tried from osx Terminal:

scala /Users/rdave/projects/test.scala

scalac /Users/rdave/projects/test.scala

And got command not found

Upvotes: 0

Views: 4066

Answers (2)

Phasmid
Phasmid

Reputation: 953

Better yet, put your code in the "standard" directory structure (your scala class would therefore end up in /Users/rdave/projects/myproject/src/main/scala/) and run sbt console. You will have access to all your code and be able to use the REPL for experimentation.

Upvotes: 1

Alex Tartan
Alex Tartan

Reputation: 6836

command not found

Is generated by the terminal, signaling that it can't find your executable

As the docs suggest:

Path and Environment
For quick access, add scala and scalac to your path. For example:

Environment     Variable        Value (example)
Unix            $SCALA_HOME     /usr/local/share/scala
                $PATH           $PATH:$SCALA_HOME/bin

After this, you will be able to call scala and scalac without any errors.

Upvotes: 2

Related Questions