-1

I'm trying to run Scala in my command line.

I checked my java, went to the Scala website, downloaded and installed it, updated my environment variables.

So far the only thing different from guides online is that the folder where sbt is installed does not include a "lib" folder.

I then run sbt command in my prompt, and I get this message:

enter image description here

It looks like I'm missing a file called build.sbt, what is this? and do i need it?

Edit:

If I press 'continue' on the picture above, I get

sbt:scalaproj> 

Which looks fine, but if i type some code, like this:

sbt:scalaproj> var a : Int = 12;

Then it returns errors:

[error] Expected ';'
[error] var a : Int = 12

What in the world is going wrong? can someone point me to a guide for writing Scala in the prompt that is not too old to work?

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
s3j80
  • 143
  • 1
  • 1
  • 9
  • 1
    **sbt** is a project manager, you need a file called `build.sbt` that defines the project. If you only want to run a REPL shell it may be better to install **Scala** itself. – Luis Miguel Mejía Suárez Jul 27 '20 at 16:20
  • yes I thought so too, but it seems to me that sbt is the only scala thing that i am able to get on the scala website. – s3j80 Jul 27 '20 at 16:21
  • and also, this build.sbt-file where should i usually find it? – s3j80 Jul 27 '20 at 16:22
  • 1
    it is not something you find. You have to create it yourself in the root directory of your project. You will have specify your project name, version and dependencies in this file. You can go on github and look at any example project to see this file. But as @LuisMiguelMejíaSuárez suggested, you should go with Scala REPL itself. If you scroll down on the scala website you will see **"Other ways to Install Scala"** – sinanspd Jul 27 '20 at 16:54
  • sbt is scala build tool which is used to build entire project. If you want to run only single scala file then use `scalac FileName.scala` and then `scala compiled_file` Read this if you want to run project using sbt. https://docs.scala-lang.org/getting-started/sbt-track/getting-started-with-scala-and-sbt-on-the-command-line.html – Vinay Mahamuni Jul 27 '20 at 16:54
  • 1
    [Here](https://www.scala-lang.org/download/) you can find all the installers, including the windows `msi` - the `build.sbt` file has to be created by you for each project, is not that you find it in someplace, but that you run **sbt** over some project which has it. – Luis Miguel Mejía Suárez Jul 27 '20 at 16:54

1 Answers1

1

Let's first understand the terminology. Scala is the language you are writing. SBT is an acronym for Scala Build Tool. Both of them have REPL.

When you call sbt in the command line, you initiate the REPL of sbt. The commands you can run there, are all commands sbt supports. You can find here the common commands. For example, if you run compile, it will compile the build.sbt located at the directory where you called the sbt command. Anyway, Scala commands WILL NOT work here. Scala commands are not sbt commands.

In order to run Scala REPL, you need to type console in the sbt REPL. You can find here the Scala REPL documentation. Within the Scala REPL you can run Scala commands.

P.S. You can find the Scala download page here.

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35