1scala(1) USER COMMANDS scala(1)
2
3
4
6 scala - Run code in the Scala 2 language
7
9 scala [ <option> ]... [ <torun> <argument>... ]
10
12 <compiler-option>
13 Any scalac option. See scalac(1).
14
15 -howtorun:<how>
16 How to execute <torun>, if it is present. Options for <how> are
17 guess (the default), script, and object.
18
19 -i Requests that a file be pre-loaded. It is only meaningful for
20 interactive shells.
21
22 -e Requests that its argument be executed as Scala code.
23
24 -savecompiled
25 Save this compiled version of scripts in order to speed up later
26 executions of the same script. When running a script, save the
27 compiled version of in a file with the same name as the script
28 but with an extension of .jar. On subsequent runs of the same
29 script, the pre-compiled .jar file will be used if it is newer
30 than the script file.
31
32 -nocompdaemon
33 Do not use the fsc offline compiler.
34
35 -D<property=value>
36 Set a Java system property. If no value is specified, then the
37 property is set to the empty string.
38
39 <torun>
40 A top-level object or a script file to run.
41
42 <argument>
43 An arguments to pass to <torun>.
44
46 The scala utility runs Scala code using a Java runtime environment.
47 The Scala code to run is specified in one of three ways:
48
49 1. With no arguments specified, a Scala shell starts and reads com‐
50 mands interactively.
51
52 2. With -howtorun:object specified, the fully qualified name of a
53 top-level Scala object may be specified. The object should pre‐
54 viously have been compiled using scalac(1).
55
56 3. With -howtorun:script specified, a file containing Scala code
57 may be specified.
58
59 If -howtorun: is left as the default (guess), then the scala command
60 will check whether a file of the specified name exists. If it does,
61 then it will treat it as a script file; if it does not, then it will
62 treat it as the name of an object.
63
64 In all three cases, arbitrary scalac options may be specified. The most
65 common option is to specify a classpath with -classpath, but see the
66 scalac(1) page for full details.
67
68 If an object is specified to run, then that object must be a top-level
69 Scala object with the specified name. The object must define a method
70 main with the following signature:
71
72 def main(args: Array[String]): Unit
73
74 The method must return a Unit value, and it must accept a String array
75 as a parameter. All arguments specified on the command line will be
76 passed as arguments to the main method.
77
78 If a script file is specified to run, then the file is read and all
79 Scala statements and declarations in the file are processed in order.
80 Any arguments specified will be available via the argsvariable.
81
82 Script files may have an optional header fthat is ignored if present.
83 There are two ways to format the header: either beginning with #! and
84 ending with !#, or beginning with ::#! and ending with ::!#.
85
86 Such a header must have each header boundary start at the beginning of
87 a line. Headers can be used to make stand-alone script files, as shown
88 in the examples below.
89
90 If scala is run from an sbaz(1) directory, then it will add to its
91 classpath any jars installed in the lib directory of the sbaz direc‐
92 tory. Additionally, if no -classpath option is specified, then scala
93 will add ".", the current directory, to the end of the classpath.
94
96 If any compiler options are specified, they must be first in the com‐
97 mand line and must be followed by a bare hypen ("-") character. If no
98 arguments are specified after the optional compiler arguments, then an
99 interactive Scala shell is started. Otherwise, either a script file is
100 run, or a pre-compiled Scala object is run. It is possible to distin‐
101 guish the last two cases by using an explicit -object or -script flag,
102 but usually the program can guess correctly.
103
105 JAVACMD
106 Specify the java command to be used for running the Scala code.
107 Arguments may be specified as part of the environment variable;
108 spaces, quotation marks, etc., will be passed directly to the
109 shell for expansion.
110
111 JAVA_HOME
112 Specify JDK/JRE home directory. This directory is used to locate
113 the java command unless JAVACMD variable set.
114
115 JAVA_OPTS
116 Specify the options to be passed to the java command defined by
117 JAVACMD.
118
119 With Java 1.5 (or newer) one may for example configure the mem‐
120 ory usage of the JVM as follows: JAVA_OPTS="-Xmx512M -Xms16M
121 -Xss16M"
122
123 With GNU Java one may configure the memory usage of the GIJ as
124 follows: JAVA_OPTS="--mx512m --ms16m"
125
127 Here are some examples of running Scala code:
128
129 Execute a Scala program generated in the current directory
130 scala hello.HelloWorld
131
132 Execute a Scala program generated in a user-defined directory classes
133 scala -classpath classes hello.HelloWorld
134
135 Execute a Scala program using a user-defined java command
136 env JAVACMD=/usr/local/bin/cacao scala -classpath classes
137 hello.HelloWorld
138
139 Execute a Scala program using JVM options
140 env JAVACMD=java JAVA_OPTS="-Dmsg=hello -enableassertions" scala
141 -classpath classes hello.HelloWorld
142
143 Here is a complete Scala script for Unix:
144
145 #!/bin/sh
146 exec scala "$0" "$@"
147 !#
148 Console.println("Hello, world!")
149 argv.toList foreach Console.println
150
151 Here is a complete Scala script for MS Windows:
152
153 ::#!
154 @echo off
155 call scala %0 %*
156 goto :eof
157 ::!#
158 Console.println("Hello, world!")
159 argv.toList foreach Console.println
160
161 If you want to use the compilation cache to speed up multiple execu‐
162 tions of the script, then add -savecompiled to the scala command:
163
164 #!/bin/sh
165 exec scala -savecompiled "$0" "$@"
166 !#
167 Console.println("Hello, world!")
168 argv.toList foreach Console.println
169
171 The scala command returns a zero exit status if it succeeds. Non zero
172 is returned in case of any error. If a script or top-level object is
173 executed and returns a value, then that return value is passed on to
174 scala.
175
177 Written by Martin Odersky and other members of the Scala team.
178
180 Report bugs to http://lampsvn.epfl.ch/trac/scala.
181
183 This is open-source software, available to you under a BSD-like
184 license. See accomponying "copyright" or "LICENSE" file for copying
185 conditions. There is NO warranty; not even for MERCHANTABILITY or FIT‐
186 NESS FOR A PARTICULAR PURPOSE.
187
189 fsc(1), sbaz(1), scalac(1), scaladoc(1), scalap(1)
190
191
192
193version 0.5 April 18, 2007 scala(1)