Showing posts with label z9805| CLASSPATH. Show all posts
Showing posts with label z9805| CLASSPATH. Show all posts

Useful Scala commands

Go to scala shell

scala
Welcome to Scala version 2.10.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).
Type in expressions to have them evaluated.
Type :help for more information.

scala>

Exit scala shell

Use exit of CTRL-D

scala> exit
warning: there were 1 deprecation warning(s); re-run with -deprecation for details
[raj@Rajkumars-MacBook-Pro ~/gitws/scalaexamples]

Execute a Scala script

cat ./o990_others/a11_Demo.scala

println("This is a demo of script")

scala ./o990_others/a11_Demo.scala
This is a demo of script

Note : A scala script do not need the code to be enclosed in class / object whereas a Scala Application does need a class / object to enclose the code

Compile Scala Application

cat src/main/scala/e11_Classes/a11_101/a11_Basic.scala

package e11_Classes.a11_101

object a11_Basic {
  def main(args: Array[String]) {
    println("This is an Application")
  }

scalac src/main/scala/e11_Classes/a11_101/a11_Basic.scala

ls -l e11_Classes/a11_101/
total 16
-rw-r--r--  1 raj  staff  645 Apr 29 20:17 a11_Basic$.class
-rw-r--r--  1 raj  staff  659 Apr 29 20:17 a11_Basic.class

Execute a scala Application

scala -cp . e11_Classes.a11_101.a11_Basic
This is an Application

Here -cp option represents the CLASSPATH


Useful sbt commands

Go to sbt console

sbt
[info] Loading global plugins from /Users/raj/.sbt/0.13/plugins
[info] Set current project to scalaexamples (in build file:/Users/raj/gitws/scalaexamples/)
>

Go to scala console from sbt

sbt
[info] Loading global plugins from /Users/raj/.sbt/0.13/plugins
[info] Set current project to scalaexamples (in build file:/Users/raj/gitws/scalaexamples/)
> console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).
Type in expressions to have them evaluated.
Type :help for more information.

scala>

Note : This also build the project and make the build targets available on CLASSPATH

Execute Scala Application

sbt
[info] Loading global plugins from /Users/raj/.sbt/0.13/plugins
[info] Set current project to scalaexamples (in build file:/Users/raj/gitws/scalaexamples/)
> run-main e11_Classes.a11_101.a11_Basic
[info] Compiling 1 Scala source to /Users/raj/gitws/scalaexamples/target/scala-2.10/classes...
[info] Running e11_Classes.a11_101.a11_Basic
This is an Application
[success] Total time: 3 s, completed Apr 29, 2016 8:24:41 PM

Note : We do not need to compile the Class as it is done automatically