-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1235 from eed3si9n/wip/recipe
[2.x] Recipe for hello world
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
How to write hello world | ||
======================== | ||
|
||
Problem | ||
------- | ||
|
||
I want to write a hello world program in Scala, and run it. | ||
|
||
Steps | ||
----- | ||
|
||
1. Create a fresh directory, like `hello_scala/` | ||
2. Create a directory named `project/` under `hello_scala/`, and create `project/build.properties` with | ||
``` | ||
sbt.version={{sbt_version}} | ||
``` | ||
3. Under `hello_scala/`, create `build.sbt`: | ||
```scala | ||
scalaVersion := "{{scala3_example_version}}" | ||
``` | ||
4. Under `hello_scala/`, create `Hello.scala`: | ||
```scala | ||
@main def main(args: String*): Unit = | ||
println(s"Hello ${args.mkString}") | ||
``` | ||
5. Navigate to `hello_scala/` from the terminal, and run `sbt`: | ||
```bash | ||
$ sbt | ||
``` | ||
6. When the prompt appears, type `run`: | ||
```scala | ||
sbt:hello_scala> run | ||
``` | ||
7. Type `exit` to exit the sbt shell: | ||
```scala | ||
sbt:hello_scala> exit | ||
``` | ||
|
||
Alternatives | ||
------------ | ||
|
||
When you're in a hurry, you can run `sbt init` in a fresh directory, and select the first template. |