installation of scala
- log in as root
- download scala : wget http://downloads.lightbend.com/scala/2.13.4/scala-2.13.4.rpm
- yum install scala-2.13.4.rpm
- verify the files of the installed package and their path: rpm -ql scala-2.13.4
- verify scala version: scala -version
Scala code runner version 2.13.4 -- Copyright 2002-2020, LAMP/EPFL and Lightbend, Inc. - 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
- 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")
}
} - compile the code: scalac first.scala
- update CLASSPATH: export CLASSPATH=.:${CLASSPATH}
- run the code: scala first
Hello world - 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
- log in as root
- remove old bintray repo file:
rm -f /etc/yum.repos.d/bintray-rpm.repo
- Download the latest repo file :
cd /etc/yum.repos.dcurl -L https://www.scala-sbt.org/sbt-rpm.repo
- install the package:
yum install sbt - verify it works:
sbt version
Create a project with sbt
- log in as a developer
- create directory structure:
cd projects/scala
mkdir sbttest
cd sbttest
mkdir -p mkdir -p src/main/scala/com/cba/testsbt - create a scala file as follows:
vi src/main/scala/com/cba/testsbt/first.scalapackage com.cba.testsbt
object first
{
def main(args:Array[String]):Unit=
{
println("Hello world of sbt adventures")}
}
Compile it:
sbt compileRun it:
sbt runcheck the jar:
ls target/scala-2.12/- Update the build settings:
vi build.sbtval 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
) - Build a jar. Note the dependencies are being resolved and artifacts are being fetched from maven repository:
sbt package - Execute the package, note the jar is having a different name now:
sbt run - 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 - If the class cannot be found, set the classpath to the current directory:
export CLASSPATH=.
scala first_2.12-1.0.jar