diff --git a/_getting-started/index.md b/_getting-started/index.md index 5db17b403c..774ef9ce36 100644 --- a/_getting-started/index.md +++ b/_getting-started/index.md @@ -10,4 +10,223 @@ redirect_from: - /scala3/getting-started.html # we deleted the scala 3 version of this page --- -{% include getting-started.md %} +The instructions below cover both Scala 2 and Scala 3. + +
+{% altDetails need-help-info-box 'Need Help?' class=help-info %} +*If you are having trouble with setting up Scala, feel free to ask for help in the `#scala-users` channel of +[our Discord](https://discord.com/invite/scala).* +{% endaltDetails %} +
+ +## Try Scala without installing anything + +To start experimenting with Scala right away, use “Scastie” in your browser. +_Scastie_ is an online “playground” where you can experiment with Scala examples to see how things work, with access to all Scala compilers and published libraries. + +> Scastie supports both Scala 2 and Scala 3, but it defaults +> to Scala 3. If you are looking for a Scala 2 snippet to play with, +> [click here](https://scastie.scala-lang.org/MHc7C9iiTbGfeSAvg8CKAA). + +## Install Scala on your computer + +Installing Scala means installing various command-line tools such as the Scala compiler and build tools. +We recommend using the Scala installer tool "Coursier" that automatically installs all the requirements, but you can still manually install each tool. + +### Using the Scala Installer (recommended way) + +The Scala installer is a tool named [Coursier](https://get-coursier.io/docs/cli-overview), whose main command is named `cs`. +It ensures that a JVM and standard Scala tools are installed on your system. +Install it on your system with the following instructions. + + +{% tabs install-cs-setup-tabs class=platform-os-options %} + + +{% tab macOS for=install-cs-setup-tabs %} +Run the following command in your terminal, following the on-screen instructions: +{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-brew %} +{% altDetails cs-setup-macos-nobrew "Alternatively, if you don't use Homebrew:" %} + {% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-default %} +{% endaltDetails %} +{% endtab %} + + + +{% tab Linux for=install-cs-setup-tabs %} + Run the following command in your terminal, following the on-screen instructions: + {% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.linux %} +{% endtab %} + + + +{% tab Windows for=install-cs-setup-tabs %} + Download and execute [the Scala installer for Windows]({{site.data.setup-scala.windows-link}}) + based on Coursier, and follow the on-screen instructions. +{% endtab %} + + + +{% tab Other for=install-cs-setup-tabs defaultTab %} + + Follow the documentation from Coursier on + [how to install and run `cs setup`](https://get-coursier.io/docs/cli-installation). +{% endtab %} + + +{% endtabs %} + + + +{% altDetails testing-your-setup 'Testing your setup' %} +Check your setup with the command `scala -version`, which should output: +```bash +$ scala -version +Scala code runner version {{site.scala-3-version}} -- Copyright 2002-2022, LAMP/EPFL +``` +If that does not work, you may need to log out and log back in (or reboot) in order for the changes to take effect. +{% endaltDetails %} + + + +Along with managing JVMs, `cs setup` also installs useful command-line tools: + +| Commands | Description | +|----------|-------------| +| `scalac` | the Scala compiler | +| `scala` | the Scala REPL and script runner | +| `scala-cli`| [Scala CLI](https://scala-cli.virtuslab.org), interactive toolkit for Scala | +| `sbt`, `sbtn` | The [sbt](https://www.scala-sbt.org/) build tool | +| `amm` | [Ammonite](https://ammonite.io/) is an enhanced REPL | +| `scalafmt` | [Scalafmt](https://scalameta.org/scalafmt/) is the Scala code formatter | + +For more information about `cs`, read +[coursier-cli documentation](https://get-coursier.io/docs/cli-overview). + +> `cs setup` installs the Scala 3 compiler and runner by default (the `scalac` and +> `scala` commands, respectively). Whether you intend to use Scala 2 or 3, +> this is usually not an issue because most projects use a build tool that will +> use the correct version of Scala irrespective of the one installed "globally". +> Nevertheless, you can always launch a specific version of Scala using +> ``` +> $ cs launch scala:{{ site.scala-version }} +> $ cs launch scalac:{{ site.scala-version }} +> ``` +> If you prefer Scala 2 to be run by default, you can force that version to be installed with: +> ``` +> $ cs install scala:{{ site.scala-version }} scalac:{{ site.scala-version }} +> ``` + +### ...or manually + +You only need two tools to compile, run, test, and package a Scala project: Java 8 or 11, +and sbt. +To install them manually: + +1. if you don't have Java 8 or 11 installed, download + Java from [Oracle Java 8](https://www.oracle.com/java/technologies/javase-jdk8-downloads.html), [Oracle Java 11](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html), + or [AdoptOpenJDK 8/11](https://adoptopenjdk.net/). Refer to [JDK Compatibility](/overviews/jdk-compatibility/overview.html) for Scala/Java compatibility detail. +1. Install [sbt](https://www.scala-sbt.org/download.html) + +## Create a "Hello World" project with sbt + +Once you have installed sbt, you are ready to create a Scala project, which +is explained in the following sections. + +To create a project, you can either use the command line or an IDE. +If you are familiar with the command line, we recommend that approach. + +### Using the command line + +sbt is a build tool for Scala. sbt compiles, runs, +and tests your Scala code. (It can also publish libraries and do many other tasks.) + +To create a new Scala project with sbt: + +1. `cd` to an empty folder. +1. Run the command `sbt new scala/scala3.g8` to create a Scala 3 project, or `sbt new scala/hello-world.g8` to create a Scala 2 project. + This pulls a project template from GitHub. + It will also create a `target` folder, which you can ignore. +1. When prompted, name the application `hello-world`. This will + create a project called "hello-world". +1. Let's take a look at what just got generated: + +``` +- hello-world + - project (sbt uses this for its own files) + - build.properties + - build.sbt (sbt's build definition file) + - src + - main + - scala (all of your Scala code goes here) + - Main.scala (Entry point of program) <-- this is all we need for now +``` + +More documentation about sbt can be found in the [Scala Book](/scala3/book/tools-sbt.html) (see [here](/overviews/scala-book/scala-build-tool-sbt.html) for the Scala 2 version) +and in the official sbt [documentation](https://www.scala-sbt.org/1.x/docs/index.html) + +### With an IDE + +You can skip the rest of this page and go directly to [Building a Scala Project with IntelliJ and sbt](/getting-started/intellij-track/building-a-scala-project-with-intellij-and-sbt.html) + + +## Open hello-world project + +Let's use an IDE to open the project. The most popular ones are IntelliJ and VSCode. +They both offer rich IDE features, but you can still use [many other editors.](https://scalameta.org/metals/docs/editors/overview.html) + +### Using IntelliJ + +1. Download and install [IntelliJ Community Edition](https://www.jetbrains.com/idea/download/) +1. Install the Scala plugin by following [the instructions on how to install IntelliJ plugins](https://www.jetbrains.com/help/idea/managing-plugins.html) +1. Open the `build.sbt` file then choose *Open as a project* + +### Using VSCode with metals + +1. Download [VSCode](https://code.visualstudio.com/Download) +1. Install the Metals extension from [the Marketplace](https://marketplace.visualstudio.com/items?itemName=scalameta.metals) +1. Next, open the directory containing a `build.sbt` file (this should be the directory `hello-world` if you followed the previous instructions). When prompted to do so, select *Import build*. + +>[Metals](https://scalameta.org/metals) is a “Scala language server” that provides support for writing Scala code in VS Code and other editors like [Atom, Sublime Text, and more](https://scalameta.org/metals/docs/editors/overview.html), using the Language Server Protocol. +> +> Under the hood, Metals communicates with the build tool by using +> the [Build Server Protocol (BSP)](https://build-server-protocol.github.io/). For details on how Metals works, see, [“Write Scala in VS Code, Vim, Emacs, Atom and Sublime Text with Metals”](https://www.scala-lang.org/2019/04/16/metals.html). + +### Play with the source code + +View these two files in your IDE: + +- _build.sbt_ +- _src/main/scala/Main.scala_ + +When you run your project in the next step, the configuration in _build.sbt_ will be used to run the code in _src/main/scala/Main.scala_. + +## Run Hello World + +If you’re comfortable using your IDE, you can run the code in _Main.scala_ from your IDE. + +Otherwise, you can run the application from a terminal with these steps: + +1. `cd` into `hello-world`. +1. Run `sbt`. This opens up the sbt console. +1. Type `~run`. The `~` is optional and causes sbt to re-run on every file save, + allowing for a fast edit/run/debug cycle. sbt will also generate a `target` directory + which you can ignore. + +When you’re finished experimenting with this project, press `[Enter]` to interrupt the `run` command. +Then type `exit` or press `[Ctrl+D]` to exit sbt and return to your command line prompt. + +## Next Steps + +Once you've finished the above tutorials, consider checking out: + +* [The Scala Book](/scala3/book/introduction.html) (see the Scala 2 version [here](/overviews/scala-book/introduction.html)), which provides a set of short lessons introducing Scala’s main features. +* [The Tour of Scala](/tour/tour-of-scala.html) for bite-sized introductions to Scala's features. +* [Learning Resources](/learn.html), which includes online interactive tutorials and courses. +* [Our list of some popular Scala books](/books.html). +* [The migration guide](/scala3/guides/migration/compatibility-intro.html) helps you to migrate your existing Scala 2 code base to Scala 3. + +## Getting Help +There are a multitude of mailing lists and real-time chat rooms in case you want to quickly connect with other Scala users. Check out our [community](https://scala-lang.org/community/) page for a list of these resources, and for where to reach out for help. diff --git a/_includes/_ja/getting-started.md b/_includes/_ja/getting-started.md deleted file mode 100644 index f200bcb759..0000000000 --- a/_includes/_ja/getting-started.md +++ /dev/null @@ -1,171 +0,0 @@ -このページは Scala 2と Scala 3の両方に対応しています。 - -## インストールなしで今すぐ Scala を試す! - -Scala を今すぐ試すにはブラウザで「Scastie」を使います。 -Scastieは Scala のサンプルコードがどのように動作するかをブラウザで簡単に試すことができるオンライン「playground」で、様々なバージョンのコンパイラと公開されているライブラリが利用できます。 - -> Scastie は Scala 2と Scala 3の両方をサポートしていますが、デフォルトでは Scala 3になっています。Scala 2のスニペットをお探しの方は、[こちら](https://scastie.scala-lang.org/MHc7C9iiTbGfeSAvg8CKAA)をご覧ください。 - -## コンピューターに Scala をインストールする - -Scala をインストールすると、コンパイラやビルドツールなどの様々なコマンドラインツールが同時にインストールされます。 -私たちは必須ツール全てを確実にインストールするために「Coursier」の使用をお勧めしますが、それらを手動でインストールすることもできます。 - -### Scala インストーラーを使う(推奨) - -Scala のインストーラーは[Coursier](https://get-coursier.io/docs/cli-overview)というツールで、コマンドは`cs`です。このツールを使うと、JVM と標準 Scala ツールがシステムにインストールされます。 -以下の手順でお使いのシステムにインストールしてください。 - - -{% tabs install-cs-setup-tabs class=platform-os-options %} - - -{% tab macOS for=install-cs-setup-tabs %} -{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-brew %} -{% altDetails cs-setup-macos-nobrew "または、Homebrewを使用しない場合は" %} - {% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-default %} -{% endaltDetails %} -{% endtab %} - - - -{% tab Linux for=install-cs-setup-tabs %} - {% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.linux %} -{% endtab %} - - - -{% tab Windows for=install-cs-setup-tabs %} - [the Scala installer for Windows]({{site.data.setup-scala.windows-link}})を、ダウンロードして実行してください。 -{% endtab %} - - - -{% tab Other for=install-cs-setup-tabs defaultTab %} - - [手順に従って `cs` ランチャーをインストール](https://get-coursier.io/docs/cli-installation)し、その次に以下を実行します。`./cs setup` -{% endtab %} - - -{% endtabs %} - - -`cs setup` は JVM の管理だけでなく、便利なコマンドラインツールもインストールします: - -- JDK (インストール済みでなければ) -- [sbt](https://www.scala-sbt.org/) ビルドツール -- [Ammonite](https://ammonite.io/), 強化された REPL -- [scalafmt](https://scalameta.org/scalafmt/), コードフォーマッター -- `scalac` (Scala 2 コンパイラー) -- `scala` (Scala 2 の REPL と script runner). - -`cs`の詳細については、[ccoursier-cliのドキュメント](https://get-coursier.io/docs/cli-overview)をご覧ください。 - -> 現在`cs setup` は Scala 2 のコンパイラとランナー(それぞれ`scalac`と`scala`コマンド)をインストールします。ほとんどのプロジェクトでは Scala 2 と Scala 3 の両方に対応したビルドツールを使用しているので、通常は問題になりません。しかし、以下の追加コマンドを実行することで、Scala 3のコンパイラとランナーをコマンドラインツールとしてインストールすることができます。 -> ``` -> $ cs install scala3-compiler -> $ cs install scala3 -> ``` - -### 手動でのインストール - -Scala プロジェクトのコンパイル、実行、テスト、パッケージ化に必要なツールは Java と sbt の2つだけです。 -Java のバージョンは8または11です。 -これらを手動でインストールするには: - -1. Java 8または11がインストールされていない場合は、[Oracle Java 8](https://www.oracle.com/java/technologies/javase-jdk8-downloads.html)、[Oracle Java 11](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html)、または[AdoptOpenJDK 8/11](https://adoptopenjdk.net/)からJavaをダウンロードしてください。Scala と Java の互換性の詳細については、[JDK Compatibility](/overviews/jdk-compatibility/overview.html)を参照してください。 -1. [sbt](https://www.scala-sbt.org/download.html)をインストールしてください。 - -## sbt で「Hello World」プロジェクトを作成する - -sbt をインストールしたら、次のセクションで説明する Scala プロジェクトを作成する準備ができました。 - -プロジェクトの作成には、コマンドラインまたはIDEを使用します。コマンドラインに慣れている方は、その方法をお勧めします。 - -### コマンドラインを使う - -sbt は、Scala のビルドツールです。sbt は、Scala のコードをコンパイルし、実行し、テストします。(sbt は、Scala コードのコンパイル、実行、テストを行います(ライブラリの公開やその他多くのタスクも可能です)。 - -sbt で新しい Scala プロジェクトを作成するには、以下の手順で行います: - -1. 空のディレクトリに`cd`する. -1. Scala 3プロジェクトを作成する場合は`sbt new scala/scala3.g8`、Scala 2プロジェクトを作成する場合は`sbt new scala/hello-world.g8`というコマンドを実行します。これは、GitHub からプロジェクトのテンプレートを引き出します。このとき"target"という名前のディレクトリが作成されますが無視してください。 -1. プロンプトが表示されたら、アプリケーションの名前を`hello-world`とします。これにより、"hello-world "というプロジェクトが作成されます。 -1. それでは、生成されたばかりのものを見てみましょう: - -``` -- hello-world - - project (sbt が利用するファイル) - - build.properties - - build.sbt (sbt のビルド定義) - - src - - main - - scala (あなたの Scala のコードはすべてここに入る) - - Main.scala (プログラムのエントリーポイント) <-- 今、必要なのはこれだけです -``` - -sbt についての詳しいドキュメントは、[Scala Book](/scala3/book/tools-sbt.html)([Scala 2バージョンはこちら](/overviews/scala-book/scala-build-tool-sbt.html))と、[sbt の公式ドキュメント](https://www.scala-sbt.org/1.x/docs/ja/index.html)に掲載されています。 - -### IDEを使う - -このページの残りの部分を読み飛ばして、[Building a Scala Project with IntelliJ and sbt](/getting-started/intellij-track/building-a-scala-project-with-intellij-and-sbt.html)に進んでも問題ありません。 - -## hello-world プロジェクトを開く - -IDE を使ってプロジェクトを開いてみましょう。最もポピュラーなものは IntelliJ と VSCode です。どちらも豊富な IDE 機能を備えていますが、他にも[多くのエディタ](https://scalameta.org/metals/docs/editors/overview.html)を使うことができます。 - -### IntelliJ を使う - -1. [IntelliJ Community Edition](https://www.jetbrains.com/idea/download/)をダウンロードしてインストールします。 -1. IntelliJ プラグインのインストール方法にしたがって、[Scala プラグインをインストール](https://www.jetbrains.com/help/idea/managing-plugins.html)します。 -1. `build.sbt`ファイルを開き、*Open as a project*を選択します。 - -### VSCode で metals を使う - -1. [VSCode](https://code.visualstudio.com/Download)をダウンロードする -1. [Marketplace](https://marketplace.visualstudio.com/items?itemName=scalameta.metals)から Metals extension をインストールする -1. 次に、build.sbt ファイルがあるディレクトリを開きます(前の指示に従った場合は、hello-world というディレクトリになるはずです)。プロンプトが表示されたら、「Import build」を選択します。 - -> ->[Metals](https://scalameta.org/metals) は、[VS Codeや Atom、Sublime Textなど](https://scalameta.org/metals/docs/editors/overview.html)のエディタで Scala のコードを書くためのサポートを提供する「Scala 言語サーバ」であり、Language Server Protocol を使用しています。 -> Metalsはバックグラウンドで[BSP(Build Server Protocol)](https://build-server-protocol.github.io/)を使用してビルドツールと通信します。Metalsの仕組みについては、[「Write Scala in VS Code, Vim, Emacs, Atom and Sublime Text with Metals」](https://www.scala-lang.org/2019/04/16/metals.html)を参照してください。 - -### ソースコードをいじってみよう - -この2つのファイルを IDE で表示します: - -- _build.sbt_ -- _src/main/scala/Main.scala_ - -次のステップでプロジェクトを実行すると、_src/main/scala/Main.scala_のコードを実行するために、_build.sbt_の設定が使われます。 - -## Hello World の実行 - -IDE の使用に慣れている場合は、IDE から_Main.scala_のコードを実行することができます。 - -または、以下の手順でターミナルからアプリケーションを実行できます: - -1. `hello-world`ディレクトリに`cd` する -1. `sbt`コマンドを実行し、sbt console を開く -1. `~run`と打ち込む。 `~` は全てのコマンドの前に追加できるコマンドで、ファイル保存を検知してコマンドを再実行してくれるため、編集・実行・デバッグのサイクルを高速に行うことができます。sbt はここでも`target`ディレクトリを生成しますが無視してください。 - -このプロジェクトの`run`を止めたければ、`[Enter]`を押して`run`コマンドを中断します。その後`exit`と入力するか`[Ctrl+D]`を押すと sbt が終了し、コマンドラインプロンプトに戻ります。 - -## 次のステップ - -上記のチュートリアルの後は以下の教材に進んでください。 - -* [The Scala Book](/scala3/book/introduction.html) (Scala 2版は[こちら](/overviews/scala-book/introduction.html))はScalaの主な機能を紹介する短いレッスンのセットを提供します。 -* [The Tour of Scala](/tour/tour-of-scala.html) Scalaの機能を一口サイズで紹介します。 -* [Learning Resources](/learn.html) オンラインのインタラクティブなチュートリアルやコースです。 -* [books](/books.html) 人気のある Scalaの 書籍を紹介します -* [The migration guide](/scala3/guides/migration/compatibility-intro.html) 既存の Scala 2コードベースを Scala 3に移行する際に役立ちます。 - -## ヘルプが必要な人は -他の Scala ユーザーとすぐに連絡を取りたい場合は、多くのメーリングリストやリアルタイムのチャットルームがあります。これらのリソースのリストや、どこに問い合わせればよいかについては、[コミュニティページ](https://scala-lang.org/community/)をご覧ください。 - -### (日本語のみ追記) -Scala について日本語で質問したい場合、Twitterでつぶやくと気づいた人が教えてくれます。 diff --git a/_includes/getting-started.md b/_includes/getting-started.md deleted file mode 100644 index e05bacfcb9..0000000000 --- a/_includes/getting-started.md +++ /dev/null @@ -1,220 +0,0 @@ -The instructions below cover both Scala 2 and Scala 3. - -
-{% altDetails need-help-info-box 'Need Help?' class=help-info %} -*If you are having trouble with setting up Scala, feel free to ask for help in the `#scala-users` channel of -[our Discord](https://discord.com/invite/scala).* -{% endaltDetails %} -
- -## Try Scala without installing anything - -To start experimenting with Scala right away, use “Scastie” in your browser. -_Scastie_ is an online “playground” where you can experiment with Scala examples to see how things work, with access to all Scala compilers and published libraries. - -> Scastie supports both Scala 2 and Scala 3, but it defaults -> to Scala 3. If you are looking for a Scala 2 snippet to play with, -> [click here](https://scastie.scala-lang.org/MHc7C9iiTbGfeSAvg8CKAA). - -## Install Scala on your computer - -Installing Scala means installing various command-line tools such as the Scala compiler and build tools. -We recommend using the Scala installer tool "Coursier" that automatically installs all the requirements, but you can still manually install each tool. - -### Using the Scala Installer (recommended way) - -The Scala installer is a tool named [Coursier](https://get-coursier.io/docs/cli-overview), whose main command is named `cs`. -It ensures that a JVM and standard Scala tools are installed on your system. -Install it on your system with the following instructions. - - -{% tabs install-cs-setup-tabs class=platform-os-options %} - - -{% tab macOS for=install-cs-setup-tabs %} -Run the following command in your terminal, following the on-screen instructions: -{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-brew %} -{% altDetails cs-setup-macos-nobrew "Alternatively, if you don't use Homebrew:" %} - {% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-default %} -{% endaltDetails %} -{% endtab %} - - - -{% tab Linux for=install-cs-setup-tabs %} - Run the following command in your terminal, following the on-screen instructions: - {% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.linux %} -{% endtab %} - - - -{% tab Windows for=install-cs-setup-tabs %} - Download and execute [the Scala installer for Windows]({{site.data.setup-scala.windows-link}}) - based on Coursier, and follow the on-screen instructions. -{% endtab %} - - - -{% tab Other for=install-cs-setup-tabs defaultTab %} - - Follow the documentation from Coursier on - [how to install and run `cs setup`](https://get-coursier.io/docs/cli-installation). -{% endtab %} - - -{% endtabs %} - - - -{% altDetails testing-your-setup 'Testing your setup' %} -Check your setup with the command `scala -version`, which should output: -```bash -$ scala -version -Scala code runner version {{site.scala-3-version}} -- Copyright 2002-2022, LAMP/EPFL -``` -If that does not work, you may need to log out and log back in (or reboot) in order for the changes to take effect. -{% endaltDetails %} - - - -Along with managing JVMs, `cs setup` also installs useful command-line tools: - -| Commands | Description | -|----------|-------------| -| `scalac` | the Scala compiler | -| `scala` | the Scala REPL and script runner | -| `scala-cli`| [Scala CLI](https://scala-cli.virtuslab.org), interactive toolkit for Scala | -| `sbt`, `sbtn` | The [sbt](https://www.scala-sbt.org/) build tool | -| `amm` | [Ammonite](https://ammonite.io/) is an enhanced REPL | -| `scalafmt` | [Scalafmt](https://scalameta.org/scalafmt/) is the Scala code formatter | - -For more information about `cs`, read -[coursier-cli documentation](https://get-coursier.io/docs/cli-overview). - -> `cs setup` installs the Scala 3 compiler and runner by default (the `scalac` and -> `scala` commands, respectively). Whether you intend to use Scala 2 or 3, -> this is usually not an issue because most projects use a build tool that will -> use the correct version of Scala irrespective of the one installed "globally". -> Nevertheless, you can always launch a specific version of Scala using -> ``` -> $ cs launch scala:{{ site.scala-version }} -> $ cs launch scalac:{{ site.scala-version }} -> ``` -> If you prefer Scala 2 to be run by default, you can force that version to be installed with: -> ``` -> $ cs install scala:{{ site.scala-version }} scalac:{{ site.scala-version }} -> ``` - -### ...or manually - -You only need two tools to compile, run, test, and package a Scala project: Java 8 or 11, -and sbt. -To install them manually: - -1. if you don't have Java 8 or 11 installed, download - Java from [Oracle Java 8](https://www.oracle.com/java/technologies/javase-jdk8-downloads.html), [Oracle Java 11](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html), - or [AdoptOpenJDK 8/11](https://adoptopenjdk.net/). Refer to [JDK Compatibility](/overviews/jdk-compatibility/overview.html) for Scala/Java compatibility detail. -1. Install [sbt](https://www.scala-sbt.org/download.html) - -## Create a "Hello World" project with sbt - -Once you have installed sbt, you are ready to create a Scala project, which -is explained in the following sections. - -To create a project, you can either use the command line or an IDE. -If you are familiar with the command line, we recommend that approach. - -### Using the command line - -sbt is a build tool for Scala. sbt compiles, runs, -and tests your Scala code. (It can also publish libraries and do many other tasks.) - -To create a new Scala project with sbt: - -1. `cd` to an empty folder. -1. Run the command `sbt new scala/scala3.g8` to create a Scala 3 project, or `sbt new scala/hello-world.g8` to create a Scala 2 project. - This pulls a project template from GitHub. - It will also create a `target` folder, which you can ignore. -1. When prompted, name the application `hello-world`. This will - create a project called "hello-world". -1. Let's take a look at what just got generated: - -``` -- hello-world - - project (sbt uses this for its own files) - - build.properties - - build.sbt (sbt's build definition file) - - src - - main - - scala (all of your Scala code goes here) - - Main.scala (Entry point of program) <-- this is all we need for now -``` - -More documentation about sbt can be found in the [Scala Book](/scala3/book/tools-sbt.html) (see [here](/overviews/scala-book/scala-build-tool-sbt.html) for the Scala 2 version) -and in the official sbt [documentation](https://www.scala-sbt.org/1.x/docs/index.html) - -### With an IDE - -You can skip the rest of this page and go directly to [Building a Scala Project with IntelliJ and sbt](/getting-started/intellij-track/building-a-scala-project-with-intellij-and-sbt.html) - - -## Open hello-world project - -Let's use an IDE to open the project. The most popular ones are IntelliJ and VSCode. -They both offer rich IDE features, but you can still use [many other editors.](https://scalameta.org/metals/docs/editors/overview.html) - -### Using IntelliJ - -1. Download and install [IntelliJ Community Edition](https://www.jetbrains.com/idea/download/) -1. Install the Scala plugin by following [the instructions on how to install IntelliJ plugins](https://www.jetbrains.com/help/idea/managing-plugins.html) -1. Open the `build.sbt` file then choose *Open as a project* - -### Using VSCode with metals - -1. Download [VSCode](https://code.visualstudio.com/Download) -1. Install the Metals extension from [the Marketplace](https://marketplace.visualstudio.com/items?itemName=scalameta.metals) -1. Next, open the directory containing a `build.sbt` file (this should be the directory `hello-world` if you followed the previous instructions). When prompted to do so, select *Import build*. - ->[Metals](https://scalameta.org/metals) is a “Scala language server” that provides support for writing Scala code in VS Code and other editors like [Atom, Sublime Text, and more](https://scalameta.org/metals/docs/editors/overview.html), using the Language Server Protocol. -> -> Under the hood, Metals communicates with the build tool by using -> the [Build Server Protocol (BSP)](https://build-server-protocol.github.io/). For details on how Metals works, see, [“Write Scala in VS Code, Vim, Emacs, Atom and Sublime Text with Metals”](https://www.scala-lang.org/2019/04/16/metals.html). - -### Play with the source code - -View these two files in your IDE: - -- _build.sbt_ -- _src/main/scala/Main.scala_ - -When you run your project in the next step, the configuration in _build.sbt_ will be used to run the code in _src/main/scala/Main.scala_. - -## Run Hello World - -If you’re comfortable using your IDE, you can run the code in _Main.scala_ from your IDE. - -Otherwise, you can run the application from a terminal with these steps: - -1. `cd` into `hello-world`. -1. Run `sbt`. This opens up the sbt console. -1. Type `~run`. The `~` is optional and causes sbt to re-run on every file save, - allowing for a fast edit/run/debug cycle. sbt will also generate a `target` directory - which you can ignore. - -When you’re finished experimenting with this project, press `[Enter]` to interrupt the `run` command. -Then type `exit` or press `[Ctrl+D]` to exit sbt and return to your command line prompt. - -## Next Steps - -Once you've finished the above tutorials, consider checking out: - -* [The Scala Book](/scala3/book/introduction.html) (see the Scala 2 version [here](/overviews/scala-book/introduction.html)), which provides a set of short lessons introducing Scala’s main features. -* [The Tour of Scala](/tour/tour-of-scala.html) for bite-sized introductions to Scala's features. -* [Learning Resources](/learn.html), which includes online interactive tutorials and courses. -* [Our list of some popular Scala books](/books.html). -* [The migration guide](/scala3/guides/migration/compatibility-intro.html) helps you to migrate your existing Scala 2 code base to Scala 3. - -## Getting Help -There are a multitude of mailing lists and real-time chat rooms in case you want to quickly connect with other Scala users. Check out our [community](https://scala-lang.org/community/) page for a list of these resources, and for where to reach out for help. diff --git a/_ja/getting-started/index.md b/_ja/getting-started/index.md index e1d4101870..b5a911766d 100644 --- a/_ja/getting-started/index.md +++ b/_ja/getting-started/index.md @@ -8,4 +8,174 @@ redirect_from: - /ja/scala3/getting-started.html # we deleted the scala 3 version of this page --- -{% include _ja/getting-started.md %} +このページは Scala 2と Scala 3の両方に対応しています。 + +## インストールなしで今すぐ Scala を試す! + +Scala を今すぐ試すにはブラウザで「Scastie」を使います。 +Scastieは Scala のサンプルコードがどのように動作するかをブラウザで簡単に試すことができるオンライン「playground」で、様々なバージョンのコンパイラと公開されているライブラリが利用できます。 + +> Scastie は Scala 2と Scala 3の両方をサポートしていますが、デフォルトでは Scala 3になっています。Scala 2のスニペットをお探しの方は、[こちら](https://scastie.scala-lang.org/MHc7C9iiTbGfeSAvg8CKAA)をご覧ください。 + +## コンピューターに Scala をインストールする + +Scala をインストールすると、コンパイラやビルドツールなどの様々なコマンドラインツールが同時にインストールされます。 +私たちは必須ツール全てを確実にインストールするために「Coursier」の使用をお勧めしますが、それらを手動でインストールすることもできます。 + +### Scala インストーラーを使う(推奨) + +Scala のインストーラーは[Coursier](https://get-coursier.io/docs/cli-overview)というツールで、コマンドは`cs`です。このツールを使うと、JVM と標準 Scala ツールがシステムにインストールされます。 +以下の手順でお使いのシステムにインストールしてください。 + + +{% tabs install-cs-setup-tabs class=platform-os-options %} + + +{% tab macOS for=install-cs-setup-tabs %} +{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-brew %} +{% altDetails cs-setup-macos-nobrew "または、Homebrewを使用しない場合は" %} + {% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-default %} +{% endaltDetails %} +{% endtab %} + + + +{% tab Linux for=install-cs-setup-tabs %} + {% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.linux %} +{% endtab %} + + + +{% tab Windows for=install-cs-setup-tabs %} + [the Scala installer for Windows]({{site.data.setup-scala.windows-link}})を、ダウンロードして実行してください。 +{% endtab %} + + + +{% tab Other for=install-cs-setup-tabs defaultTab %} + + [手順に従って `cs` ランチャーをインストール](https://get-coursier.io/docs/cli-installation)し、その次に以下を実行します。`./cs setup` +{% endtab %} + + +{% endtabs %} + + +`cs setup` は JVM の管理だけでなく、便利なコマンドラインツールもインストールします: + +- JDK (インストール済みでなければ) +- [sbt](https://www.scala-sbt.org/) ビルドツール +- [Ammonite](https://ammonite.io/), 強化された REPL +- [scalafmt](https://scalameta.org/scalafmt/), コードフォーマッター +- `scalac` (Scala 2 コンパイラー) +- `scala` (Scala 2 の REPL と script runner). + +`cs`の詳細については、[ccoursier-cliのドキュメント](https://get-coursier.io/docs/cli-overview)をご覧ください。 + +> 現在`cs setup` は Scala 2 のコンパイラとランナー(それぞれ`scalac`と`scala`コマンド)をインストールします。ほとんどのプロジェクトでは Scala 2 と Scala 3 の両方に対応したビルドツールを使用しているので、通常は問題になりません。しかし、以下の追加コマンドを実行することで、Scala 3のコンパイラとランナーをコマンドラインツールとしてインストールすることができます。 +> ``` +> $ cs install scala3-compiler +> $ cs install scala3 +> ``` + +### 手動でのインストール + +Scala プロジェクトのコンパイル、実行、テスト、パッケージ化に必要なツールは Java と sbt の2つだけです。 +Java のバージョンは8または11です。 +これらを手動でインストールするには: + +1. Java 8または11がインストールされていない場合は、[Oracle Java 8](https://www.oracle.com/java/technologies/javase-jdk8-downloads.html)、[Oracle Java 11](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html)、または[AdoptOpenJDK 8/11](https://adoptopenjdk.net/)からJavaをダウンロードしてください。Scala と Java の互換性の詳細については、[JDK Compatibility](/overviews/jdk-compatibility/overview.html)を参照してください。 +1. [sbt](https://www.scala-sbt.org/download.html)をインストールしてください。 + +## sbt で「Hello World」プロジェクトを作成する + +sbt をインストールしたら、次のセクションで説明する Scala プロジェクトを作成する準備ができました。 + +プロジェクトの作成には、コマンドラインまたはIDEを使用します。コマンドラインに慣れている方は、その方法をお勧めします。 + +### コマンドラインを使う + +sbt は、Scala のビルドツールです。sbt は、Scala のコードをコンパイルし、実行し、テストします。(sbt は、Scala コードのコンパイル、実行、テストを行います(ライブラリの公開やその他多くのタスクも可能です)。 + +sbt で新しい Scala プロジェクトを作成するには、以下の手順で行います: + +1. 空のディレクトリに`cd`する. +1. Scala 3プロジェクトを作成する場合は`sbt new scala/scala3.g8`、Scala 2プロジェクトを作成する場合は`sbt new scala/hello-world.g8`というコマンドを実行します。これは、GitHub からプロジェクトのテンプレートを引き出します。このとき"target"という名前のディレクトリが作成されますが無視してください。 +1. プロンプトが表示されたら、アプリケーションの名前を`hello-world`とします。これにより、"hello-world "というプロジェクトが作成されます。 +1. それでは、生成されたばかりのものを見てみましょう: + +``` +- hello-world + - project (sbt が利用するファイル) + - build.properties + - build.sbt (sbt のビルド定義) + - src + - main + - scala (あなたの Scala のコードはすべてここに入る) + - Main.scala (プログラムのエントリーポイント) <-- 今、必要なのはこれだけです +``` + +sbt についての詳しいドキュメントは、[Scala Book](/scala3/book/tools-sbt.html)([Scala 2バージョンはこちら](/overviews/scala-book/scala-build-tool-sbt.html))と、[sbt の公式ドキュメント](https://www.scala-sbt.org/1.x/docs/ja/index.html)に掲載されています。 + +### IDEを使う + +このページの残りの部分を読み飛ばして、[Building a Scala Project with IntelliJ and sbt](/getting-started/intellij-track/building-a-scala-project-with-intellij-and-sbt.html)に進んでも問題ありません。 + +## hello-world プロジェクトを開く + +IDE を使ってプロジェクトを開いてみましょう。最もポピュラーなものは IntelliJ と VSCode です。どちらも豊富な IDE 機能を備えていますが、他にも[多くのエディタ](https://scalameta.org/metals/docs/editors/overview.html)を使うことができます。 + +### IntelliJ を使う + +1. [IntelliJ Community Edition](https://www.jetbrains.com/idea/download/)をダウンロードしてインストールします。 +1. IntelliJ プラグインのインストール方法にしたがって、[Scala プラグインをインストール](https://www.jetbrains.com/help/idea/managing-plugins.html)します。 +1. `build.sbt`ファイルを開き、*Open as a project*を選択します。 + +### VSCode で metals を使う + +1. [VSCode](https://code.visualstudio.com/Download)をダウンロードする +1. [Marketplace](https://marketplace.visualstudio.com/items?itemName=scalameta.metals)から Metals extension をインストールする +1. 次に、build.sbt ファイルがあるディレクトリを開きます(前の指示に従った場合は、hello-world というディレクトリになるはずです)。プロンプトが表示されたら、「Import build」を選択します。 + +> +>[Metals](https://scalameta.org/metals) は、[VS Codeや Atom、Sublime Textなど](https://scalameta.org/metals/docs/editors/overview.html)のエディタで Scala のコードを書くためのサポートを提供する「Scala 言語サーバ」であり、Language Server Protocol を使用しています。 +> Metalsはバックグラウンドで[BSP(Build Server Protocol)](https://build-server-protocol.github.io/)を使用してビルドツールと通信します。Metalsの仕組みについては、[「Write Scala in VS Code, Vim, Emacs, Atom and Sublime Text with Metals」](https://www.scala-lang.org/2019/04/16/metals.html)を参照してください。 + +### ソースコードをいじってみよう + +この2つのファイルを IDE で表示します: + +- _build.sbt_ +- _src/main/scala/Main.scala_ + +次のステップでプロジェクトを実行すると、_src/main/scala/Main.scala_のコードを実行するために、_build.sbt_の設定が使われます。 + +## Hello World の実行 + +IDE の使用に慣れている場合は、IDE から_Main.scala_のコードを実行することができます。 + +または、以下の手順でターミナルからアプリケーションを実行できます: + +1. `hello-world`ディレクトリに`cd` する +1. `sbt`コマンドを実行し、sbt console を開く +1. `~run`と打ち込む。 `~` は全てのコマンドの前に追加できるコマンドで、ファイル保存を検知してコマンドを再実行してくれるため、編集・実行・デバッグのサイクルを高速に行うことができます。sbt はここでも`target`ディレクトリを生成しますが無視してください。 + +このプロジェクトの`run`を止めたければ、`[Enter]`を押して`run`コマンドを中断します。その後`exit`と入力するか`[Ctrl+D]`を押すと sbt が終了し、コマンドラインプロンプトに戻ります。 + +## 次のステップ + +上記のチュートリアルの後は以下の教材に進んでください。 + +* [The Scala Book](/scala3/book/introduction.html) (Scala 2版は[こちら](/overviews/scala-book/introduction.html))はScalaの主な機能を紹介する短いレッスンのセットを提供します。 +* [The Tour of Scala](/tour/tour-of-scala.html) Scalaの機能を一口サイズで紹介します。 +* [Learning Resources](/learn.html) オンラインのインタラクティブなチュートリアルやコースです。 +* [books](/books.html) 人気のある Scalaの 書籍を紹介します +* [The migration guide](/scala3/guides/migration/compatibility-intro.html) 既存の Scala 2コードベースを Scala 3に移行する際に役立ちます。 + +## ヘルプが必要な人は +他の Scala ユーザーとすぐに連絡を取りたい場合は、多くのメーリングリストやリアルタイムのチャットルームがあります。これらのリソースのリストや、どこに問い合わせればよいかについては、[コミュニティページ](https://scala-lang.org/community/)をご覧ください。 + +### (日本語のみ追記) +Scala について日本語で質問したい場合、Twitterでつぶやくと気づいた人が教えてくれます。 diff --git a/scala3/getting-started.md b/scala3/getting-started.md deleted file mode 100644 index b82ed44938..0000000000 --- a/scala3/getting-started.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -layout: singlepage-overview -title: Getting Started -languages: ["ja"] ---- - -{% include getting-started.md %}