From 8dfba137cb36e2cdb78eb7016cc5ae0a09b9b1ec Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Wed, 18 Sep 2024 23:59:46 -0400 Subject: [PATCH] [2.x] Recipe for hello world --- src/reference/SUMMARY.md | 2 ++ src/reference/recipes/hello-world.md | 42 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/reference/recipes/hello-world.md diff --git a/src/reference/SUMMARY.md b/src/reference/SUMMARY.md index a6a8923d..46764260 100644 --- a/src/reference/SUMMARY.md +++ b/src/reference/SUMMARY.md @@ -21,5 +21,7 @@ - [Caching](concepts/caching.md) - [Reference]() - [Remote cache setup](reference/remote-cache-setup.md) +- [Recipes]() + - [Write hello world](recipes/hello-world.md) - [Appendix]() - [Setup notes](setup-notes.md) diff --git a/src/reference/recipes/hello-world.md b/src/reference/recipes/hello-world.md new file mode 100644 index 00000000..6f3d0319 --- /dev/null +++ b/src/reference/recipes/hello-world.md @@ -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.