1scala(1)                         USER COMMANDS                        scala(1)
2
3
4

NAME

6       scala - Run code in the Scala 2 language
7

SYNOPSIS

9       scala  [ <option> ]... [ <torun> <argument>... ]
10

PARAMETERS

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, jar, and object.
18
19       -i <file>
20              Requests that a file be pre-loaded.  It is only  meaningful  for
21              interactive shells.
22
23       -e <string>
24              Requests that its argument be executed as Scala code.
25
26       -savecompiled
27              Save this compiled version of scripts in order to speed up later
28              executions of the same script.  When running a script, save  the
29              compiled  version in a file with the same name as the script but
30              with an extension of .jar.   On  subsequent  runs  of  the  same
31              script,  the  pre-compiled .jar file will be used if it is newer
32              than the script file.
33
34       -nocompdaemon
35              Do not use the fsc offline compiler.
36
37       -nc    Same as -nocompdaemon.
38
39       -Dproperty=value
40              Set a Java system property.  If no value is specified, then  the
41              property is set to the empty string.
42
43       <torun>
44              A top-level object or a script file to run.
45
46       <argument>
47              An arguments to pass to <torun>.
48

DESCRIPTION

50       The  scala  utility  runs  Scala code using a Java runtime environment.
51       The Scala code to run is specified in one of three ways:
52
53          1.  With no arguments specified, a Scala shell starts and reads com‐
54              mands interactively.
55
56          2.  With  -howtorun:object  specified, the fully qualified name of a
57              top-level Scala object may be specified.  The object should pre‐
58              viously have been compiled using scalac(1).
59
60          3.  With  -howtorun:script  specified,  a file containing Scala code
61              may be specified.
62
63       If -howtorun: is left as the default (guess), then  the  scala  command
64       will  check  whether  a file of the specified name exists.  If it does,
65       then it will treat it as a script file; if it does not,  then  it  will
66       treat it as the name of an object.
67
68       In all three cases, arbitrary scalac options may be specified. The most
69       common option is to specify a classpath with -classpath,  but  see  the
70       scalac(1) page for full details.
71
72       If  an object is specified to run, then that object must be a top-level
73       Scala object with the specified name.  The object must define a  method
74       main with the following signature:
75
76       def main(args: Array[String]): Unit
77
78       The  method must return a Unit value, and it must accept a String array
79       as a parameter.  All arguments specified on the command  line  will  be
80       passed as arguments to the main method.
81
82       If  a  script  file  is specified to run, then the file is read and all
83       Scala statements and declarations in the file are processed  in  order.
84       Any arguments specified will be available via the argsvariable.
85
86       Script  files  may  have an optional header that is ignored if present.
87       There are two ways to format the header: either beginning with  #!  and
88       ending with !#, or beginning with ::#! and ending with ::!#.
89
90       Such  a header must have each header boundary start at the beginning of
91       a line.  Headers can be used to make stand-alone script files, as shown
92       in the examples below.
93
94       When  running a script or using -e, an already running compilation dae‐
95       mon (fsc) is used, or a new one started on demand.   The  -nocompdaemon
96       or -nc option can be used to prevent this.
97
98       If no -classpath option is specified, then scala will add ".", the cur‐
99       rent directory, to the end of the classpath.
100

OPTIONS

102       If any compiler options are specified, they must be first in  the  com‐
103       mand  line and must be followed by a bare hyphen ("-") character. If no
104       arguments are specified after the optional compiler arguments, then  an
105       interactive Scala shell is started.  Otherwise, either a script file is
106       run, or a pre-compiled Scala object is run.  It is possible to  distin‐
107       guish  the last two cases by using an explicit -object or -script flag,
108       but usually the program can guess correctly.
109

ENVIRONMENT

111       JAVACMD
112              Specify the java command to be used for running the Scala  code.
113              Arguments  may be specified as part of the environment variable;
114              spaces, quotation marks, etc., will be passed  directly  to  the
115              shell for expansion.
116
117       JAVA_HOME
118              Specify JDK/JRE home directory. This directory is used to locate
119              the java command unless JAVACMD variable set.
120
121       JAVA_OPTS
122              Specify the options to be passed to the java command defined  by
123              JAVACMD.
124
125              With  Java 1.5 (or newer) one may for example configure the mem‐
126              ory usage of the JVM  as  follows:  JAVA_OPTS="-Xmx512M  -Xms16M
127              -Xss16M"
128

EXAMPLES

130       Here are some examples of running Scala code:
131
132       Execute a Scala program generated in the current directory
133              scala hello.HelloWorld
134
135       Execute a Scala program generated in a user-defined directory classes
136              scala -classpath classes hello.HelloWorld
137
138       Execute a Scala program using a user-defined java command
139              env   JAVACMD=/usr/local/bin/cacao   scala   -classpath  classes
140              hello.HelloWorld
141
142       Execute a Scala program using JVM options
143              env JAVACMD=java JAVA_OPTS="-Dmsg=hello -enableassertions" scala
144              -classpath classes hello.HelloWorld
145
146       Here is a complete Scala script for Unix:
147
148       #!/bin/sh
149       exec scala "$0" "$@"
150       !#
151       Console.println("Hello, world!")
152       args.toList foreach Console.println
153
154       Here is a complete Scala script for MS Windows:
155
156       ::#!
157       @echo off
158       call scala %0 %*
159       goto :eof
160       ::!#
161       Console.println("Hello, world!")
162       args.toList foreach Console.println
163
164       If  you  want  to use the compilation cache to speed up multiple execu‐
165       tions of the script, then add -savecompiled to the scala command:
166
167       #!/bin/sh
168       exec scala -savecompiled "$0" "$@"
169       !#
170       Console.println("Hello, world!")
171       args.toList foreach Console.println
172

EXIT STATUS

174       The scala command returns a zero exit status if it succeeds.  Non  zero
175       is  returned  in case of any error.  If a script or top-level object is
176       executed and returns a value, then that return value is  passed  on  to
177       scala.
178

AUTHOR

180       Written by Martin Odersky and other members of the Scala team.
181

REPORTING BUGS

183       Report bugs to https://github.com/scala/bug/issues.
184
186       This is open-source software, available to you under the Apache License
187       2.0. See accompanying "copyright" or "LICENSE" file for copying  condi‐
188       tions.  There  is  NO warranty; not even for MERCHANTABILITY or FITNESS
189       FOR A PARTICULAR PURPOSE.
190

SEE ALSO

192       fsc(1), scalac(1), scaladoc(1), scalap(1)
193
194
195
196version 0.5                       April 2007                          scala(1)
Impressum