cbaWorkflow : Scala 2.13.4 installation

installation of scala

  1. log in as root
  2. download scala :  wget http://downloads.lightbend.com/scala/2.13.4/scala-2.13.4.rpm
  3. yum install scala-2.13.4.rpm
  4. verify the files of the installed package and their path: rpm -ql scala-2.13.4
  5. verify scala version: scala -version
    Scala code runner version 2.13.4 -- Copyright 2002-2020, LAMP/EPFL and Lightbend, Inc.
  6. if scala was upgraded the link in /usr/bin may be missing, the actual install is happening at /usr/share/scala, so either create a link to it, or include /usr/share/scala/bin in your path
  7. Log in as a developer user and create a test program: vi first.scala

    object first
    {
             def main(args: Array[String]):Unit=
             {
                              println("Hello world")
             }
    }

  8. compile the code: scalac first.scala
  9. update CLASSPATH:  export CLASSPATH=.:${CLASSPATH}
  10. run the code:  scala first
    Hello world
  11. Verify scala runner is working properly: scala
    Welcome to Scala 2.13.4 (OpenJDK 64-Bit Server VM, Java 1.8.0_282).
    Type in expressions for evaluation. Or try :help.
    scala> var variables: scala.collection.immutable.Map[String,String] = Map()
    scala> variables += ("path"→"/home/user")
    scala> variables += ("lib"->"my library")
    scala> val b=variables.contains("path")
    scala> val b: Boolean = true
    scala> if(b==true) print(variables("path"))
    /home/user
    scala>:q


Installation is successful if it is the steps have been successful.

Installation of sbt

  1. log in as root
  2. remove old bintray repo file:
    rm -f /etc/yum.repos.d/bintray-rpm.repo
  3. Download the latest repo file :
    cd /etc/yum.repos.d
    curl -L https://www.scala-sbt.org/sbt-rpm.repo
  4. install the package:
    yum install sbt
  5. verify it works:
    sbt version

Create a project with sbt

  1. log in as a developer
  2.  create directory structure:
    cd projects/scala
    mkdir sbttest
    cd sbttest
    mkdir -p mkdir -p src/main/scala/com/cba/testsbt
  3. create a scala file as follows:
    vi src/main/scala/com/cba/testsbt/first.scala

    package com.cba.testsbt

    object first
    {
             def main(args:Array[String]):Unit=
             {
                       println("Hello world of sbt adventures")

              }

    }

  4. Compile it:
    sbt compile

  5. Run it:
    sbt run

  6. check the jar: 
    ls target/scala-2.12/

  7. Update the build settings:
    vi build.sbt

    val derby = "org.apache.derby" % "derby" % "10.4.1.3"

    ThisBuild / organization := "com.cba"
    ThisBuild / scalaVersion := "2.12.14"
    ThisBuild / version := "1.0"

    lazy val root = (project in file("."))
    .settings(
    name := "First",
    libraryDependencies += derby
    )

  8. Build a jar. Note the dependencies are being resolved and artifacts are being fetched from maven repository:
    sbt package
  9. Execute the package, note the jar is having a different name now:
    sbt run
  10. copy the jar to the home directory and execute it outside of sbt:
    [dataexplorer1@r01edge sbttest]$ cp target/scala-2.12/first_2.12-1.0.jar $HOME
    [dataexplorer1@r01edge sbttest]$ cd $HOME
    [dataexplorer1@r01edge ~]$ scala first_2.12-1.0.jar
    Hello world of sbt adventures

  11. If the class cannot be found, set the classpath to the current directory:
    export CLASSPATH=.
    scala first_2.12-1.0.jar