You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/cookbooks/intro.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@ sidebar_position: 1
5
5
6
6
# Cookbook
7
7
8
-
This part contains a set of recipes how to use scala-cli in certain situations. The cookbooks are intended to provide a solution to task at hand without providing too many details.
8
+
This section of the documentation contains a set of recipes that show how to use `scala-cli` in certain situations.
9
+
The recipes are intended to provide a solution to the task at hand, but also without going into great detail.
9
10
10
-
For more in-depth analysis please check out provided[Guides](../guides/intro.md)
11
+
For more in-depth analysis, please check out our[Guides](../guides/intro.md)
Copy file name to clipboardExpand all lines: website/docs/cookbooks/scala-docker.md
+15-9Lines changed: 15 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,21 @@
1
1
---
2
-
title: Package Scala application as a docker image
2
+
title: Packaging Scala applications as Docker images
3
3
sidebar_position: 5
4
4
---
5
5
6
-
# Package Scala application as a docker image
6
+
Scala CLI can create an executable application and package it into a Docker image.
7
7
8
-
ScalaCLI can create an executable application and package it into a docker image.
9
-
10
-
Here is a simple piece of code that will be executed in the docker container.
8
+
For example, here's a simple piece of code that will be executed in a Docker container:
11
9
12
10
```scala title=HelloDocker.scala
13
11
objectHelloDockerextendsApp {
14
12
println("Hello from Docker")
15
13
}
16
14
```
17
15
18
-
Passing `--docker` to the `package` sub-command generates a docker image. The docker image name parameter `--docker-image-repository` is mandatory.
16
+
Passing `--docker` to the `package` sub-command generates a Docker image. When creating a Docker image, the `--docker-image-repository` parameter is mandatory.
19
17
20
-
The following command will generate`hello-docker` image with `latest` tag:
18
+
The following command generates a`hello-docker` image with the`latest` tag:
Copy file name to clipboardExpand all lines: website/docs/cookbooks/scala-jvm.md
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,12 @@
1
1
---
2
-
title: Test your code with different Java versions
2
+
title: Testing your code with different Java versions
3
3
sidebar_position: 4
4
4
---
5
5
6
-
# Test your code with different Java versions
6
+
You can use Scala CLI to test your code compatibility with various versions of `java`, with a key point being that manual installation of a JDK/SDK is not required(!).
7
+
Scala CLI automatically downloads the Java version you specify.
7
8
8
-
You can use Scala CLI to test your code compatibility with various versions of `java` (no manual installation of jdk or sdk is required). It automatically downloads the specified version of Java.
9
-
10
-
The following snippet uses the new method `Files.writeString` from Java 11.
9
+
As an example, the following snippet uses the new method `Files.writeString` from Java 11:
11
10
12
11
```scala title=Main.scala
13
12
importjava.nio.file.Files
@@ -21,7 +20,7 @@ object Main extends App {
21
20
}
22
21
```
23
22
24
-
Pass `--jvm` to the `scala-cli` command to run your application with the specified java version.
23
+
To use Java 11 to run this application, pass the following `--jvm`option to the `scala-cli` command:
By default, the `package` sub-command generates a lightweight JAR.
22
+
By default, the `package` sub-command generates a lightweight JAR that contains only your bytecode. This is how you create a lightweight JAR named `DetectOsApp.jar`:
23
23
24
24
```bash
25
25
scala-cli package DetectOsApp.scala
@@ -30,37 +30,38 @@ Wrote DetectOsApp, run it with
30
30
./DetectOsApp
31
31
-->
32
32
33
-
Lightweight JARs require the `java` command to be available, and access to internet if dependencies need to be downloaded.
33
+
Lightweight JARs require the `java` command to be available, and access to the internet, if dependencies need to be downloaded. This is how you run it on macOS:
34
34
35
35
```bash
36
-
# Run DetectOsApp on MacOs
36
+
# Run DetectOsApp on macOS
37
37
./DetectOsApp
38
38
# os: Mac OS X
39
39
```
40
40
41
-
In the previous example, a Lightweight JAR that was built in a MacOs environment could also run on Linux.
41
+
The lightweight JAR that was just built on macOS can also run on Linux:
42
42
43
43
```bash
44
44
# Run DetectOsApp on Linux
45
45
./DetectOsApp
46
46
# os: Linux
47
47
```
48
48
49
-
Scala-cli supports building Lightweight JARs in the MacOS, Linux, and Windows environments.
50
-
JARs built on macOS and Linux are portable between these two OSs. The Lightweight JARs built on Windows can only be run on Windows.
49
+
`scala-cli` supports building Lightweight JARs in the macOS, Linux, and Windows environments.
50
+
JARs built on macOS and Linux are portable between these two operating systems.
51
+
Lightweight JARs built on Windows can only be run on Windows.
51
52
52
53
53
54
### Assemblies
54
-
Passing `--assembly` to the `package` sub-command generates so-called "assemblies" or "fat JARs".
55
+
Passing `--assembly` to the `package` sub-command generates so-called "assemblies," or "fat JARs":
55
56
56
57
```bash
57
58
scala-cli package --assembly DetectOsApp.scala
58
59
```
59
60
60
-
Assemblies also require the `java` command to be available in the `PATH`. As all dependencies are packaged into the assembly, nothing gets downloaded upon the first run and no internet access is required.
61
+
Assemblies also require the `java` command to be available in the `PATH`. But in this case, all of the dependencies that are needed are packaged into the assembly, so nothing gets downloaded upon the first run, and no internet access is required.
Copy file name to clipboardExpand all lines: website/docs/cookbooks/scala-scripts.md
+15-9Lines changed: 15 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,17 @@
1
1
---
2
-
title: Use scala-cli to run Scala Scripts
2
+
title: Using scala-cli to run Scala Scripts
3
3
sidebar_position: 3
4
4
---
5
5
6
6
## Scala Scripts
7
7
8
-
Scala Scripts are files containing Scala code without main method required. These codes of Scala do not require build-tools configurations. To run Scala Scripts very quickly without waiting for warn-up build-tools, you can use `scala-cli`.
8
+
Scala scripts are files that contain Scala code without a main method.
9
+
These source code files don't require build-tool configurations.
10
+
To run Scala scripts very quickly without waiting the need for build tools, use `scala-cli`.
9
11
10
12
### Run
11
13
12
-
You can use `scala-cli` to run Scala scripts (no further setup is required):
14
+
For example, given this simple script:
13
15
14
16
```scala title=HelloScript.sc
15
17
valsv= scala.util.Properties.versionNumberString
@@ -18,6 +20,8 @@ val message = s"Hello from Scala ${sv}, Java ${System.getProperty("java.version"
18
20
println(message)
19
21
```
20
22
23
+
You can run it directly with `scala-cli` — there's no need for a build tool or additional configuration:
24
+
21
25
```bash
22
26
scala-cli run HelloScript.sc
23
27
```
@@ -26,8 +30,7 @@ scala-cli run HelloScript.sc
26
30
Hello from Scala .*, Java .*
27
31
-->
28
32
29
-
30
-
Alternatively, add a "shebang" header to your script, make your script executable, and execute it directly. `scala-cli` needs to be installed for this to work.
33
+
Alternatively, you can add a "shebang" header to your script, make it executable, and execute it directly with `scala-cli`. For example, given this script with a header that invokes `scala-cli`:
31
34
32
35
```scala title=HelloScriptSheBang.sc
33
36
#!/usr/bin/env scala-cli
@@ -41,6 +44,7 @@ def printMessage(): Unit =
41
44
printMessage()
42
45
```
43
46
47
+
You can make it executable and then run it like this:
44
48
45
49
```bash
46
50
chmod +x HelloScriptSheBang.sc
@@ -52,7 +56,7 @@ chmod +x HelloScriptSheBang.sc
52
56
Hello from Scala .*, Java .*
53
57
-->
54
58
55
-
It is also possible to pass command-line arguments to the script
59
+
You can also pass commandline arguments to Scala scripts:
56
60
57
61
```scala title=ScriptArguments.sc
58
62
#!/usr/bin/env scala-cli
@@ -69,14 +73,16 @@ chmod +x ScriptArguments.sc
69
73
bar
70
74
-->
71
75
76
+
As shown, command line arguments are accessed through the special `args` variable.
77
+
72
78
73
79
## Features
74
80
75
-
All the features from non-scripts work for Scala scripts too, such as waiting for changes (watch mode), dependencies menagement, packaging, compiling and many others.
81
+
All of the features shown for non-scripts work for Scala scripts as well, such as waiting for changes (watch mode), dependency menagement, packaging, compiling, etc.
76
82
77
83
### Package
78
84
79
-
Run `package` to the Scala CLI to package your script to a lightweight executable JAR file.
85
+
For example, run the `package` sub-command to package your script as a lightweight executable JAR file:
80
86
81
87
```bash
82
88
scala-cli package HelloScript.sc
@@ -89,7 +95,7 @@ Hello from Scala .*, Java .*
89
95
90
96
### Watch mode
91
97
92
-
Pass `--watch` to the Scala CLI to watch all sources for changes, and re-run them upon changes.
98
+
As another example, pass `--watch` to `scala-cli`to watch all source files for changes, and then re-run them when there is a change:
0 commit comments